重新调整(自动)matplotlib 中绘图的限制
Re-adjusting (automatically) limits on plot in matplotlib
有没有办法让 matplotlib 知道重新计算绘图的最佳边界?
我的问题是,我正在手动计算一堆箱线图,将它们放在图中的不同位置。最后,一些箱线图超出了图框。我现在可以对一些 xlim 和 ylim 进行硬编码,但我想要一个更通用的解决方案。
我在想的是你说 "ok plt I am done plotting, now please adjust the bounds so that all my data is nicely within the bounds" 的功能。
这可能吗?
编辑:
答案是肯定的。
后续问题:也可以对刻度进行此操作吗?
您想使用 matplotlib 的自动轴缩放。您可以使用 axes.axis
with the "auto" input or axes.set_autoscale_on
ax.axis('auto')
ax.set_autoscale_on()
如果只想自动缩放 x 轴或 y 轴,可以使用 set_autoscaley_on
或 set_autoscalex_on
。
有没有办法让 matplotlib 知道重新计算绘图的最佳边界?
我的问题是,我正在手动计算一堆箱线图,将它们放在图中的不同位置。最后,一些箱线图超出了图框。我现在可以对一些 xlim 和 ylim 进行硬编码,但我想要一个更通用的解决方案。
我在想的是你说 "ok plt I am done plotting, now please adjust the bounds so that all my data is nicely within the bounds" 的功能。
这可能吗?
编辑: 答案是肯定的。
后续问题:也可以对刻度进行此操作吗?
您想使用 matplotlib 的自动轴缩放。您可以使用 axes.axis
with the "auto" input or axes.set_autoscale_on
ax.axis('auto')
ax.set_autoscale_on()
如果只想自动缩放 x 轴或 y 轴,可以使用 set_autoscaley_on
或 set_autoscalex_on
。