Version 3.1.2
matplotlib

Related Topics

Set default y-axis tick labels on the rightΒΆ

We can use rcParams["ytick.labelright"] = False (default False) and rcParams["ytick.right"] = False (default False) and rcParams["ytick.labelleft"] = True (default True) and rcParams["ytick.left"] = True (default True) to control where on the axes ticks and their labels appear. These properties can also be set in the .matplotlib/matplotlibrc.

Traceback (most recent call last):
  File "/build/matplotlib-mO9dyQ/matplotlib-3.1.2/examples/ticks_and_spines/tick_label_right.py", line 1
    ============================================
    ^
SyntaxError: invalid syntax
============================================
Set default y-axis tick labels on the right
============================================

We can use :rc:`ytick.labelright` (default False) and :rc:`ytick.right`
(default False) and :rc:`ytick.labelleft` (default True) and :rc:`ytick.left`
(default True) to control where on the axes ticks and their labels appear.
These properties can also be set in the ``.matplotlib/matplotlibrc``.

"""
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['ytick.right'] = plt.rcParams['ytick.labelright'] = True
plt.rcParams['ytick.left'] = plt.rcParams['ytick.labelleft'] = False

x = np.arange(10)

fig, (ax0, ax1) = plt.subplots(2, 1, sharex=True, figsize=(6, 6))

ax0.plot(x)
ax0.yaxis.tick_left()

# use default parameter in rcParams, not calling tick_right()
ax1.plot(x)

plt.show()

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery