[IPython-User] [IPython-user] matplotlib under ipython

Jon Olav Vik jonovik@gmail....
Fri Jun 18 14:14:37 CDT 2010

Neil Best <nbest <at> ci.uchicago.edu> writes:

> In [1]: x = randn(10000)
> In [2]: hist(x, 100)
> Out[2]: 
> (array([  4,   3,   1,   0,   0,   1,   3,   3,   6,  12,   9,  10,  11,

This plots the histogram in a new figure, since there doesn't exist one yet. 
When I run this on Windows XP with the --pylab switch, the figure is shown on 
screen right away. Note that pyplot.hist (which pylab imports) differs from 
np.histogram; the latter returns only the bin counts and leaves you to do the 
plotting, whereas the former has plotting as its main purpose.

> In [3]: figure()
> Out[3]: <matplotlib.figure.Figure object at 0x2d145f0>

This creates a new, blank figure. The previous one no longer has any references 
to it, I'm afraid.

> In [4]: plot()
> Out[4]: []

This adds nothing to the plot...

> In [5]: savefig('test.png')  #produces a file with axes but no chart

...and this saves your figure with no data plotted.

> If I start ipython without the pylab profile (sh instead), import what I
> need manually setting the backend to 'macosx', then a window does appear. 
> Can anyone tell me what is going on here and how it is supposed to work /
> what makes the most sense for interactive work?

Interactive work with graphical desktop: you don't need to explicitly call 
figure() except when you want a new figure. clf() will clear the current figure 
if you need to. Noninteractively, or if graphics is not available, I run 
IPython without --pylab and do:

import matplotlib as mpl
from pylab import * # or just what you need, e.g. figure, subplot, savefig

> Along those lines is there
> a convenient way to get pylab and sh profile behaviors at the same time? 

I'm not sure what you mean here.

Hope this helps, 
Jon Olav

More information about the IPython-User mailing list