I just discovered that in using pylab you can plot an array or list of number vs the list lenght by default.
Let’s say we have a list of point like [2,2,3,4,5,5,6,10, 23,45,58,42,12]
points = [2,2,3,4,5,5,6,10,23,45,58,42,12]
well to plot this you just have to
pylab.plot(points)
and this is the results:
The whole script in python
import pylab
points = [2,2,3,4,5,5,6,10,23,45,58,42,12]
pylab.plot(points)
pylab.show()
The last one is needed to show the window, which will happen automatically if you are running the script using ipython with the pylab option.
I just discovered by chance. I always thought that to plot you need x and y, but of course it’s possible to infer the x if you just one to plot only the points, cause each point in the list has a “Cartesian coordinates” embedded, i.e. [0,2];[1,2];[2,3];[3,4];… etc.
July 31, 2009 at 4:28 pm
Nice, I didn’t know of this trick.
Which one do you prefer between R and pylab, to create plots?
While pylab has many options to produce nice graphics and it is easier to do a lot of things with python, I prefer the ggplot2 library from R, because with pylab it takes too much time to produce fancy plots.
July 31, 2009 at 4:56 pm
Well, I don’t use R and I’m quite ok with pylab. It does the job :).
It’s a little bit tricky at the beginning 🙂
August 10, 2009 at 3:14 pm
One thing I really dislike of matplotlib is that you can’t plot an array of strings directly:
>>> plot(array(‘h o l a’.split())
ValueError
Instead, you have to plot on range(len(<array_of_strings)) and then assign yticks labels manually.
October 8, 2009 at 2:35 pm
Hi, I am write a short 15 minutes talk on pylab. Do you have any idea, or suggestions?
cheers!!
October 9, 2009 at 10:34 am
Sorry dude, nothing ready to share.
October 15, 2009 at 9:44 am
Thanks anyway, here it is the talk:
– http://bioinfoblog.it/?p=14