[IPython-user] Setting the linewidth with Gnuplot2

Fernando Perez Fernando.Perez at colorado.edu
Thu Sep 30 11:38:21 CDT 2004

Andrea Riciputi schrieb:
> Same IPython version here. Using only plot doesn't do the trick because 
> Gnuplot.Data is the key here. Surely Fernando explained to me the 
> reason behind this behaviour, but I can't remember it.
> If you want to create your plots interactively you can use:
> In [4]: plot(Gnuplot.Data(x,sin(x), with="lines ls 20"))
> it works from the ipython prompt. If you think that is too much typing 
> you can always redefine your own plot function.

Thanks for helping with this, Andrea.

The reason why the 'with' statment _must_ be used with a Data() constructor, 
is because gnuplot really only knows how to plot PlotItem instances.  The 
ipython plot() command builds on the fly Data PlotItem instances for you in 
the common cases, but in order to do that it plays a lot of funky tricks with 
argument parsing.  Since with is a keyword, you can't interlace it with 
positional arguments, so the following can not be done:

plot(x1,y1,with='lines ls 20',x2,y2,with='lines ls 10')

Python simply doesn't allow this.  Using Data() calls, you can do it as:

plot(Data(x1,y1,with='lines ls 20'),Data(x2,y2,with='lines ls 10'))

I tried to make plot() as automatic and 'smart' as possible, but there's a 
limit to what I can do within valid python :)

Consider the naked plot(array1,array2,...) calls useful for quick exploration, 
and explicit Data() constructions the way to do more carefully tuned plots 
(for publications, talks, etc.)



More information about the IPython-user mailing list