我在同一个图中有两个箱线图。出于样式原因,轴应该具有相同的长度,以便图形框是正方形的。我尝试使用 set_aspect
方法,但轴因范围而差异太大
结果很糟糕。
是否可以有 1:1 的轴,即使它们没有相同数量的点?
最佳答案
您可以使用 Axes.set_aspect如果将纵横比设置为轴限制的比率,则可以执行此操作。这是一个例子:
from matplotlib.pyplot import figure, show
fig = figure()
ax0 = fig.add_subplot(1,2,1)
ax0.set_xlim(10., 10.5)
ax0.set_ylim(0, 100.)
ax0.set_aspect(.5/100)
ax1 = fig.add_subplot(1,2,2)
ax1.set_xlim(0., 1007)
ax1.set_ylim(0, 12.)
x0, x1 = ax1.get_xlim()
y0, y1 = ax1.get_ylim()
ax1.set_aspect((x1-x0)/(y1-y0))
show()
可能有更简单的方法,但我不知道。
关于python - Matplotlib 方形箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506647/