The Chaco plotting toolkit for Python includes examples that show how to dynamically update existing plots. However, my application requires that I dynamically create and destroy plots depending on the data. I am new to programming with Chaco and Traits, so a simple example that illustrates how to do this would be really helpful.
The Chaco plotting toolkit for Python includes examples that show how to dynamically update
Share
This is a bit late, but here’s an example that creates and destroys Chaco plots. The main interface is
PlotSelector, which defines some fake data and radio buttons to switch between two different plot styles (line and bar plots).This example uses a Traits event to signal when to close a plot, and then handles that signal with
PlotController. There may be a better way to close the window, but I couldn’t find one.Edit: Updated imports for newer versions of Traits, Chaco, and Enable (ETS 4 instead of 3).
Note that the main interface (
PlotSelector) callsconfigure_traits(starts application), while the plots are viewed withedit_traits(called from within application). Also, note that this example callsedit_traitsfromPlotControllerinstead of calling it from the model. You could instead move the view fromPlotControllertoBasicPlotand set the handler method of that view toPlotController.Finally, if you don’t need to totally destroy the plot window, then you may want to look at the
Plotobject’sdelplotmethod, which destroys the *sub*plot (here the line plot or bar plot).I hope that helps.