Shift module usage¶
Shift y axis¶
In this section, shift.yaxis()
is demonstrated by using the following plot:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.0, 12, 0.1)
y = 0.1 * x * np.sin(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, color='blue', label='plot 1')
ax.hlines(y=0, xmin=0, xmax=30, linewidth=1)
ax.set_ylabel('Plot 1', color='blue')
ax.set_xlim(0.0, 12.0)
plt.tight_layout()
plt.show()
When you want to shift y = 0 to the center of figure, use shift.yaxis()
:
import numpy as np
import matplotlib.pyplot as plt
from mpl_axes_aligner import shift
x = np.arange(0.0, 12, 0.1)
y = 0.1 * x * np.sin(x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, color='blue', label='plot 1')
ax.hlines(y=0, xmin=0, xmax=30, linewidth=1)
ax.set_ylabel('Plot 1', color='blue')
ax.set_xlim(0.0, 12.0)
# Adjust the plotting range of two y axes
org = 0.0 # Origin
pos = 0.5 # Position the origins is aligned
expand = True # Switch the aligning method
shift.yaxis(ax, org, pos, expand)
plt.tight_layout()
plt.show()
Origins (org
)¶
The second argument of shift.yaxis()
(org
) is the origin which you want to align.
Relative position (pos
)¶
The third argument of shift.yaxis()
(pos
) is the relative position which the origin is aligned.
When expand = True
, pos
should satisfy the condition , otherwise, pos
should satisfy the condition .
When pos
is nearly 0, the origin is shifted to bottom, when pos
is nearly 1, on the other hand, the origin is shifted to top.
When pos
is 0.5, the origin is aligned at the center of figure.
Shifting method (expand
)¶
The last argument of shift.yaxis()
(expand
) toggle the origin shift method.
When expand = True
, the plotting range is adjusted without reducing plotting range:
When ,
When ,
When expand = False
, the plotting range is simply shifted:
Where, is the relative position of origin, and are the initial plotting range, and and are the calculated plotting range.
Shift x axis¶
shift.xaxis()
adjust the plotting range of x axis.
The usage is same as y axis.