wx backup show figure (WAS: general matplotlib usage questions)

On Thu, Nov 20, 2008 at 5:22 PM, Christopher Barker

try wxPython -- it's easy to install and works well.

Thanks - it does seem nicer (doesn't have the mouse over resizing)...

However I have one problem where a figure I create in a function
doesn't show up:
# this is how I create a figure in a function
In [20]: def test_func():
   ....: f = figure()
   ....: ax = f.add_subplot(111)
   ....: ax.plot([1,2,3,4],[1,2,3,4])
   ....: f.show()
   ....: return f
   ....:
In [21]: test_func()
Out[21]: <matplotlib.figure.Figure object at 0x2168c8d0>
# shows a blank (grey) canvas with no axes
In [23]: _21.show()
# ^^ does nothing
In [25]: gcf().show()
# ^^ does nothing
In [26]: f2 = figure(1)
# ^^ now it appears?

So what am I doing wrong? How can I programmatically display a figure
(ie without knowing the number in advance to do figure(n)?)

Cheers

Robin

Are you running ipython in pylab mode? See

  http://matplotlib.sourceforge.net/users/shell.html

and

  http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show

···

On Thu, Nov 20, 2008 at 1:29 PM, Robin <robince@...287...> wrote:

On Thu, Nov 20, 2008 at 5:22 PM, Christopher Barker

try wxPython -- it's easy to install and works well.

Thanks - it does seem nicer (doesn't have the mouse over resizing)...

However I have one problem where a figure I create in a function
doesn't show up:
# this is how I create a figure in a function

One more thought -- if you are in pylab mode (so "interactive" is
turned on) if you are making your draw calls through the api, as you
are in this example, you will need to call draw after the plot
commands, eg

  ax.plot(something)
  f.canvas.draw()

This is explained in some detail in the shell page I pointed you to in
my last post.

JDH

···

On Thu, Nov 20, 2008 at 1:29 PM, Robin <robince@...287...> wrote:

On Thu, Nov 20, 2008 at 5:22 PM, Christopher Barker

try wxPython -- it's easy to install and works well.

Thanks - it does seem nicer (doesn't have the mouse over resizing)...

However I have one problem where a figure I create in a function
doesn't show up:
# this is how I create a figure in a function
In [20]: def test_func():
  ....: f = figure()
  ....: ax = f.add_subplot(111)
  ....: ax.plot([1,2,3,4],[1,2,3,4])
  ....: f.show()
  ....: return f
  ....:

Right, that's it - with wx I need to use canvas.draw... I was aware of
the need to use something, but with Tk was previously using
figure.show (possibly incorrectly having read the documentation)-
which doesn't have any effect in the wx case.

Thanks very much to everyone for the prompt responses today!

Cheer

Robin

···

On Thu, Nov 20, 2008 at 8:14 PM, John Hunter <jdh2358@...287...> wrote:

One more thought -- if you are in pylab mode (so "interactive" is
turned on) if you are making your draw calls through the api, as you
are in this example, you will need to call draw after the plot
commands, eg

ax.plot(something)
f.canvas.draw()