Zhozer
Zhozer

Reputation: 125

Python: How to update plot

I created a graphic with matplotlib using subplot, so

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
.
.
.
t = np.arange(0.0, 30.0, 0.01)
self.axes.plot(t)

Now, when I press a button I want to update the graph, but it seems that I cannot just use self.axes.plot(t) inside the function. How can I do that?

Upvotes: 0

Views: 90

Answers (2)

Bennett Brown
Bennett Brown

Reputation: 5383

Try self.figure.canvas.draw() if you want to force the figure to be updated.

Upvotes: 1

tacaswell
tacaswell

Reputation: 87376

The calls to Axes functions do not automatically trigger a re-draw (unlike the plt functions). You just need to add a

self.figure.canvas.draw()

call.

Upvotes: 1

Related Questions