我使用matplotib的Axes API绘制一些图形。我画的一条线代表了理论上的预期线。它在原来的y和x限制之外没有意义。我想要的是matlplotlib在自动调整限制时忽略它。我以前做的是检查当前的限制,然后绘制并重置限制。问题是,当我绘制第三个图时,极限值会与理论线一起重新计算,这会真正扩展图形。
# Boilerplate
from matplotlib.figure import Figure
from matplotlib.backends.backend_pdf import FigureCanvasPdf
from numpy import sin, linspace
fig = Figure()
ax = fig.add_subplot(1,1,1)
x1 = linspace(-1,1,100)
ax.plot(x1, sin(x1))
ax.plot(x1, 3*sin(x1))
# I wish matplotlib would not consider the second plot when rescaling
ax.plot(x1, sin(x1/2.0))
# But would consider the first and last
canvas_pdf = FigureCanvasPdf(fig)
canvas_pdf.print_figure("test.pdf")
最明显的方法就是手动设置你想要的限制。(例如
ax.axis([xmin, xmax, ymin, ymax])
)如果你不想费心手动找出极限,你有两个选择。。。
正如一些人(tillsten,Yann和Vorticity)所提到的,如果你能在最后一次绘制出你想忽略的函数,那么你可以在绘制之前禁用自动缩放,或者将
scaley=False
kwarg传递给plot
注意,你可以调整最后一个图的
zorder
,这样它就画在“中间”,如果你想控制它的话。如果不想依赖于顺序,而只想指定要根据其自动缩放的行的列表,则可以执行以下操作:(注意:如果处理的是
Line2D
对象,而不是一般的matplotlib艺术家,则这是一个简化版本。)使用scalex/scaley kw arg:
使用
autolim=False
参数可以忽略LineCollection
objects:相关问题 更多 >
编程相关推荐