mpl_axes_aligner.align module

mpl_axes_aligner.align.xaxes(ax1, org1, ax2, org2, pos=None)

Adjust the plotting range of two x axes to align the origins with the position.

Parameters:
  • ax1 (matplotlib.axes.Axes) – First axis object of matplotlib.
  • org1 (float) – Origin of first axis to be aligned.
  • ax2 (matplotlib.axes.Axes) – Second axis object of matplotlib.
  • org2 (float) – Origin of second axis to be aligned.
  • pos (float or None, optional) – Relative position to align the origins [0 < pos < 1]. When pos is None, the origins are aligned to the middle of them.
Raises:
  • TypeError – If ‘ax1’ and/or ‘ax2’ are not the Axes object of matplotlib.
  • ValueError – If ‘pos’ is less than or equal to 0, or more than or equal to 1.

Examples

>>> import matplotlib.pyplot as plt
>>> from mpl_axes_aligner import align
>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(111)
>>> ax2 = ax1.twiny()
>>> ax1.set_xlim(-1.0, 0.0)
(-1.0, 0.0)
>>> ax2.set_xlim(0.0, 1.0)
(0.0, 1.0)
>>> align.xaxes(ax1, -0.3, ax2, 0.3, 0.5)
>>> ax1.get_xlim()
(-1.0, 0.4)
>>> ax2.get_xlim()
(-0.4, 1.0)
mpl_axes_aligner.align.yaxes(ax1, org1, ax2, org2, pos=None)

Adjust the plotting range of two y axes to align the origins with the position.

Parameters:
  • ax1 (matplotlib.axes.Axes) – First axis object of matplotlib.
  • org1 (float) – Origin of first axis to be aligned.
  • ax2 (matplotlib.axes.Axes) – Second axis object of matplotlib.
  • org2 (float) – Origin of second axis to be aligned.
  • pos (float or None, optional) – Relative position to align the origins [0 < pos < 1]. When pos is None, the origins are aligned to the middle of them.
Raises:
  • TypeError – If ‘ax1’ and/or ‘ax2’ are not the Axes object of matplotlib.
  • ValueError – If ‘pos’ is less than or equal to 0, or more than or equal to 1.

Examples

>>> import matplotlib.pyplot as plt
>>> from mpl_axes_aligner import align
>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(111)
>>> ax2 = ax1.twinx()
>>> ax1.set_ylim(-1.0, 0.0)
(-1.0, 0.0)
>>> ax2.set_ylim(0.0, 1.0)
(0.0, 1.0)
>>> align.yaxes(ax1, -0.3, ax2, 0.3, 0.5)
>>> ax1.get_ylim()
(-1.0, 0.4)
>>> ax2.get_ylim()
(-0.4, 1.0)