I have figures that require very high resolution, therefore I cannot use subplots with multiple axis (results in ValueError: Image size of 102400x6400 pixels is too large). However, I still want all the figures to share the y axis, as one would do with plt.subplots(sharey=True)
. In this case I am not concerned about only displaying one y axis, as would be the result with subplots. Rather, I want the ticks to be at the same position and the distances between them be the same.
Asked
Active
Viewed 556 times
2

timbmg
- 3,192
- 7
- 34
- 52
1 Answers
3
Of course you can simply set the same limits to both axes manually. And in fact that would be the solution I would recommend when producing high quality output.
ax1.set_xlim(xmin, xmax)
ax2.set_xlim(xmin, xmax)
Calculating xmin
and xmax
can be automated depending on the use case.
If a completely automated solution is desired or if true sharing is desired, you can share axes after their creation.
import numpy as np
import matplotlib.pyplot as plt
x1 = np.arange(6)
y1 = np.tile([1,2],3)
x2 = np.arange(5,11)
y2 = np.tile([6,8],3)
fig1, ax1 = plt.subplots()
fig2, ax2 = plt.subplots()
ax1.plot(x1,y1)
ax2.plot(x2,y2)
ax1.get_shared_x_axes().join(ax1, ax2)
ax1.get_shared_y_axes().join(ax1, ax2)
ax2.autoscale()
plt.show()

Venkatachalam
- 16,288
- 9
- 49
- 77

ImportanceOfBeingErnest
- 321,279
- 53
- 665
- 712