python - How to reset NavigatonToolbar "history" when re-plotting data on the same axis? -


i have wxpython application uses matplotlib plotting data repeatedly. code looks this:

import matplotlib matplotlib.use('wxagg') matplotlib.figure import figure matplotlib.backends.backend_wxagg import figurecanvaswxagg figcanvas, \ navigationtoolbar2wxagg navigationtoolbar  self.fig = figure((4,5), dpi = 100, facecolor = "white") self.canvas = figcanvas(self.panel, -1, self.fig) self.toolbar = navigationtoolbar(self.canvas) self.axes = self.fig.add_subplot(111) 

everytime want plot something, set x , y , do:

self.axes.plot(x,y, color = self.colours[i], label = text) self.canvas.draw() 

as can see, have navigationtoolbar bound canvas. when want plot new graph, call:

self.axes.clear() self.axes.plot(x,y, color = self.colours[i], label = text) self.canvas.draw() 

here comes problem: if use toolbar's tools (zoom, steps, pan, etc) when i'm visualizing plot, "historic" of toolbar won't reset when plot new graph later. if try use toolbar in new graph, views toolbar use (when click "home" or "step") views of old plot.

i'm kinda new matplotlib , i'm doing wrong. can me out this? in advance, , sorry grammar mistakes, english not mother language.

you might try:

self.toolbar._views.clear() self.toolbar._positions.clear() self.toolbar._update_view() # maybe don't need 

i should stress un-documented , reaching in , poking @ innards of library, there no guarantee if works now, work in future (or warning stop working).

have @ code in matplotlib/backend_bases.py how navigationtoolbar2 (the parent class of wx version) works.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -