|
From: Sterling S. <sm...@fu...> - 2013-10-11 16:52:53
|
Skip,
Here are some lines from an application I have written.
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
In the setup:
self.canvas = FigureCanvasGTKAgg(self.figure)
self.canvas.set_size_request(600,600)
self.canvas.show()
#Pack the canvas in a parent container
self.vbox0.pack_start(self.canvas, True, True)
At the event where I want the plot to update:
self.canvas.draw()
For a faster responding application, be sure to check out the matplotlib animation examples with blitting, as I built my application without that knowledge, and haven't found the time to go back and fix it...
-Sterling
On Oct 11, 2013, at 9:25AM, Skip Montanaro wrote:
> I want to use matplotlib as a component of a larger, event-driven GTK
> app. That means pylab.show is (I think) not the way to go, as it
> starts up its own event loop which doesn't return. I've tried to clear
> and plot in my event handler, but my plot is never displayed.
>
> My initialization code looks like this:
>
> matplotlib.use("GtkAgg")
> ....
> self.figure = matplotlib.figure.Figure()
> self.plot = self.figure.add_subplot(111)
> self.plot.set_axisbelow(True)
> self.figure.tight_layout()
>
> My event handler computes a new set of points (about a dozen x/y
> pairs) and plots them:
>
> points = ... generate a list of (x, y) tuples ...
> print points
> self.plot.clear()
> self.plot.plot([x for x, y in points], [y for x, y in points])
>
> Every time my event handler is called, it prints the points (I see
> them in my xterm), but the plot is never drawn.
>
> I looked at this example:
>
> http://matplotlib.org/examples/user_interfaces/embedding_in_gtk2.html
>
> but it does something with a key press handler that seems very
> artificial, and not at all like how my application will interact with
> its environment. Can someone point me to the correct spot in the
> documentation or some examples that don't require the user to type at
> the application?
>
> Thanks,
>
> Skip
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|