I have a solution that I used in 0.6.8, and should work in 0.8.9, which you might like. This is my first post so I hope it makes some sense. I wanted to be able to update the canvas without the overhead of creating a new Figure. I edited the qt_mpl_canvas.py file to allow me to refresh the canvas at will. Here are the necessary pieces:
In <home>\AppData\Local\Enthought\Canopy\User\Lib\site-packages\enaml\qt\qt_mpl_canvas.py add this function to the QtMPLCanvas class:
def on_action_set_refresh(self, content):
self.refresh_mpl_widget()
Now in your .enaml file, create this class definition:
class RefreshableMPLCanvas(MPLCanvas):
#: Toggle this to refresh the canvas
refresh = Bool(False)
def snapshot(self):
""" Get the snapshot dict for the MPLCanvas."""
snap = super(RefreshableMPLCanvas, self).snapshot()
snap['refresh'] = self.refresh
return snap
def bind(self):
""" Bind the change handlers for the MPLCanvas"""
super(RefreshableMPLCanvas, self).bind()
self.publish_attributes('refresh')
Now when you create your MPL canvas in the .enaml file, link to a Figure as usual (in this case waveform.Figure), but also subscribe to a boolean (in this case waveform.refresh):
RefreshableMPLCanvas: canvas:
figure = waveform.figure
refresh<<waveform.refresh
When you want to refresh the canvas now (where you were doing self.figure.canvas.draw() before) just do:
refresh=not refresh
This will trigger a change event on the boolean and update the canvas.
I suspect there is probably a cleaner way to do this using explicit events, rather than flipping a boolean like I am, but this works for me.