Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79456

Re: Matplotlib: getting a figure to show without plt.show()

From Peter Pearson <pkpearson@nowhere.invalid>
Newsgroups comp.lang.python
Subject Re: Matplotlib: getting a figure to show without plt.show()
Date 2014-10-22 16:38 +0000
Message-ID <caq4rpF3vveU1@mid.individual.net> (permalink)
References <caorpjFo1amU1@mid.individual.net> <mailman.15064.1413974302.18130.python-list@python.org>

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Matplotlib: getting a figure to show without plt.show() Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-22 04:57 +0000
  Re: Matplotlib: getting a figure to show without plt.show() Peter Otten <__peter__@web.de> - 2014-10-22 12:38 +0200
    Re: Matplotlib: getting a figure to show without plt.show() Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-22 16:38 +0000

csiph-web