Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Re: Matplotlib: getting a figure to show without plt.show() Date: 22 Oct 2014 16:38:17 GMT Lines: 52 Message-ID: References: X-Trace: individual.net KCW4Z6DBuXmgQDygTnkVGQCdJUrM2QUhfHONjgqGmmg46CoyUi Cancel-Lock: sha1:RV3eT2lQsBEjmPotc6Oxth5/R8s= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:79456 On Wed, 22 Oct 2014 12:38:02 +0200, Peter Otten wrote: > Peter Pearson wrote: [snip] >> def callback(event): >> global n, first >> fig = plt.figure(2) >> fig.clear() >> plt.plot([0,1],[0,n]) >> n += 1 # (Pretending something changes from one plot to the next.) >> if first: >> first = False >> plt.show() >> else: >> fig.canvas.draw() >> >> Can someone tell me the right way? [snip] > def callback(event): > global n, fig2 > > if fig2 is None: > fig2 = plt.figure(2) > > fig2.clear() > fig2.gca().plot([0, .5, 1], [0, 1/n, 1]) > fig2.show() Thank you for pointing out two useful things: * I like fig2.gca().plot better than plt.plot, since it makes it clear that I'm talking about fig2 and not some other part of the vast and inscrutable plt kingdom. * fig2.show is different from plt.show, and in fact this solves my problem exactly, since fig2.show returns immediately. By the way, I will dispense with your "if fig2 is None" test. In real life, I say something like fig2 = plt.figure("Packet Sizes"). If a figure named "Packet Sizes" doesn't exist, plt.figure creates it, otherwise it returns a pointer to the existing figure -- *and* it titles the figure's window with "Packet Sizes" rather than "2". [snip] > As I'm not an expert for matplotlib you might also post your question on the > matplotlib mailing list. Sound advice. Next time. Thanks again. -- To email me, substitute nowhere->runbox, invalid->com.