samedi 11 septembre 2010

Where is my plot?

Let's go to the first plot in ipython!
I just copy-past from the web something very promising:
ipython -pylab
Will import the modules I will need for most of my purposes. Nice!
And then, from within ipython:
x = arange(10)
y = x**2
plot(x,y)
That's it!
but... nothing appears!
On the Ubuntu, a nice window with a parabolic function, but in Mac, nothing!
Only a nice message like this one: 

Out[3]: [<matplotlib.lines.Line2D object at 0x103f139d0>]
 

But Linux gave the same, so it doesn't seems to be an error.
After quite one hour Googling all around, I found that for some strange reason my output device is wrongly set. In the Python language, it is called a backend, and some information can be found here:

This is determined by a value set in the matplotlibrc files. One is the default, coming with the matplotlib distribution, another one can be defined in the user folder.
It seems that the default value in my case is Agg, but for the interactivity it should be TkAgg.

So in a file named ~/.matplotlib/matplotlibrc I put:
backend      : TkAgg

And I saw a very nice parabolic plot! And what a surprise: the plot is dynamic, I can change the axes, make close-up, and DIRECTLY SAVE IN PS OR PDF file (IDL users know why capitalize here...).

1 commentaire:

  1. Once Qt4 is installed, better choose Qt4Agg as backend, it allows to dynamically change the style of the plot and ass x- and y-titles...

    RépondreSupprimer