擅长:python、mysql、java
<p>与<code>set_data</code>类似,您可以使用<code>set_text</code>(参见此处的文档:<a href="http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.text.Text.set_text">http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.text.Text.set_text</a>)。</p>
<p>所以首先</p>
<pre><code>text = plt.text(x, y, "Some text")
</code></pre>
<p>然后在循环中:</p>
<pre><code>text.set_text("Some other text")
</code></pre>
<p>在您的示例中,它可能看起来像:</p>
<pre><code>for t in range(10):
if t == 0:
points, = ax.plot(x, y, marker='o', linestyle='None')
text = plt.text(1, 5, "Loops passed: 0")
else:
new_x = ... # x updated
new_y = ... # y updated
points.set_data(new_x, new_y)
text.set_text("Loops passed: {0}".format(t))
plt.pause(0.5)
</code></pre>