擅长:python、mysql、java
<p>Matplotlib在创建图形等方面有很多开销,甚至在保存到pdf之前也是如此。因此,如果你的绘图相似,你可以通过重用元素来保护很多“设置”,就像你在matplotlib的动画示例中所看到的一样。在</p>
<p>在本例中,可以重用图形和轴:</p>
<pre><code>import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
X = range(10)
Y = [ x**2 for x in X ]
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
for n in range(100):
ax.clear() # or even better just line.remove()
# but should interfere with autoscaling see also below about that
line = ax.plot(X, Y)[0]
fig.savefig("test.pdf")
</code></pre>
<p>请注意,这没有多大帮助。通过重用这些行,您可以节省更多:</p>
^{pr2}$
<p>对我来说,这个速度几乎是初始示例的两倍。这只是一个选项,如果你做了相似的情节,但如果他们非常相似,它可以加快很多事情。<a href="http://matplotlib.sourceforge.net/examples/animation/index.html" rel="nofollow">matplotlib animation examples</a>可能对这种优化有启发。在</p>