<p>我使用matplotib的Axes API绘制一些图形。我画的一条线代表了理论上的预期线。它在原来的y和x限制之外没有意义。我想要的是matlplotlib在自动调整限制时忽略它。我以前做的是检查当前的限制,然后绘制并重置限制。问题是,当我绘制第三个图时,极限值会与理论线一起重新计算,这会真正扩展图形。</p>
<pre><code># 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")
</code></pre>