当您使用sharex和sharey时,设置绘图方面的问题就会出现。
一种解决方法是仅不使用共享轴。例如,您可以这样做:
from pylab import *figure()subplot(121, aspect='equal')plot([1, 2, 3], [1, 2, 3])subplot(122, aspect='equal')plot([1, 2, 3], [1, 2, 3])show()
但是,更好的解决方法是更改“ adjustable”键warg …您想要Adjustable
=’box’,但是当您使用共享轴时,它必须是Adjustable =’datalim’(并将其设置回’box’ ‘给出一个错误)。
但是,还有第三个选项
adjustable可以处理这种情况:
adjustable="box-forced"。
例如:
from pylab import *figure()ax1 = subplot(121, aspect='equal', adjustable='box-forced')plot([1, 2, 3], [1, 2, 3])subplot(122, aspect='equal', adjustable='box-forced', sharex=ax1, sharey=ax1)plot([1, 2, 3], [1, 2, 3])show()
或者采用更现代的风格(请注意:答案的这一部分在2010年将无法使用):
import matplotlib.pyplot as pltfig, axes = plt.subplots(ncols=2, sharex=True, sharey=True)for ax in axes: ax.plot([1, 2, 3], [1, 2, 3]) ax.set(adjustable='box-forced', aspect='equal')plt.show()
无论哪种方式,您都会获得类似于以下内容的信息:



