Matplotlib animation with blit -- how to update plot title?
<p>I use matplotlib to animate a plot, by copying the background and blitting:</p>

<pre><code>f = Figure(tight_layout=True)
canvas = FigureCanvasTkAgg(f, master=pframe)
canvas.get_tk_widget().pack()
ax = f.add_subplot(111)
# Set inial plot title
title = ax.set_title("First title")
canvas.show()
# Capture the background of the figure
background = canvas.copy_from_bbox(ax.bbox)
line, = ax.plot(x, y)
canvas._tkcanvas.pack()
</code></pre>

<p>Periodically I update the plot:</p>

<pre><code># How to update the title here?
line.set_ydata(new_data)
ax.draw_artist(line)
canvas.blit(ax.bbox)
</code></pre>

<p>How could I update -- as efficiently as possible, the plot title every time I update the plot?</p>

<p>Edit:</p>

<pre><code>title.set_text("New title")
ax.draw_artist(title)
</code></pre>

<p>either before or after</p>

<pre><code>canvas.blit(ax.bbox)
</code></pre>

<p>does not update the title. I think somehow I should redraw the <code>title</code> artist, or I should only capture the graph, as <code>blit(ax.bbox)</code> overwrites the entire title plot area including the title.</p>

<p>The following draws the plot and allows you to make changes,</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1,1)
ax.plot(np.linspace(0.,10.,100))
title = ax.set_title("First title")
plt.show(block=False)
</code></pre>

<p>The title can then be updated using,</p>

<pre><code>title.set_text("Second title")
plt.draw()
</code></pre>

python animation matplotlib blit