Beginning Python Visualization??

Hi,

Beginning Python Visualization: Crafting Visual Transformation Scripts
by Shai Vaingast
http://www.amazon.com/Beginning-Python-Visualization-Transformation-Professionals/dp/1430218436/ref=sr_1_1?ie=UTF8&s=books&qid=1244158389&sr=8-1

Has anyone seen/read this book? I am looking for a good
hardcopy reference for matplotlib and associated tools.

While the gallery on the matplotlib site is a good way to learn, I
would like a reference guide that I could easily print out or
a tutorial of sorts, or possibly this book.

Thanks,
Esmail

ps: here's an example of the sort of thing I'd like to learn and
     know about.

Someone recently generously shared this code with me on the python
list. While I have used pylab/matplotlib a bit, I didn't know about
ion() (line 12), nor am I sure about what is happening on line 19 and
21, does plot return a list? Why is it subscripted to? Hadn't seen
draw() before either, though I know show() .. these sort of things I
am curious to learn about before I see them in code for the first
time.

      1 #!/usr/bin/env python
      2
      3 from pylab import *
      4
      5 # of elements
      6 ELEMS = 250
      7 # initial positions
      8
      9 x0 = rand(ELEMS)
     10 y0 = rand(ELEMS)
     11
     12 ion() # interactive on
     13
     14 for t in linspace(0, 1, 100):
     15 x = x0 + 0.1*cos(t)
     16 y = y0 + 0.1*sin(t)
     17
     18 if t == 0: # first time calling
     19 h = plot(x,y,'ro')
     20 else:
     21 h[0].set_data(x,y)
     22
     23 draw()

pps: I slightly reformatted/modified the original code.

Someone recently generously shared this code with me on the python

since I was the one to share this with you, I might be able to answer a couple questions. :slight_smile:

list. While I have used pylab/matplotlib a bit, I didn’t know about

ion() (line 12),

ion() sets interactive mode on, so that the plot will update and show before the script is done. I usually use the pylab mode of ipython, so I don’t have to use this, but I put it in to work with the regular python interpreter.

nor am I sure about what is happening on line 19 and

21, does plot return a list?

18 if t == 0: # first time calling

19 h = plot(x,y,‘ro’)

20 else:

21 h[0].set_data(x,y)

it returns a list of line-type objects. since you are plotting a lot of dots, but one (invisible) line, then there is only one element in this list. If you had passed a 2D array into plot, then it would plot several lines, with possibly different properties. You can set the properties directly by calling the various set_ methods on the line-type object. In this case, the first call (when t==0) I make a regular plot, and get the object. After that, I set the data on the object directly, and then draw (so that it draws immediately). This is much faster than doing another plot command.

There may be better ways to do this animation, but I do it this way most of the time.

Why is it subscripted to? Hadn’t seen

draw() before either, though I know show() … these sort of things I

am curious to learn about before I see them in code for the first

time.

actually, that’s how I learned most of it…by seeing it in code at some point. :slight_smile:

hope this helps,

		bb
···

On Jun 4, 2009, at 19:48 , Esmail wrote:

Brian Blais

bblais@…1129…

http://web.bryant.edu/~bblais

Have you tried the official docs? While they are not complete, they do
cover a number of things you mention that you have not seen before
(ion, draw, tutorial, etc.)

  HTML: http://matplotlib.sourceforge.net/users/index.html
  PDF: http://matplotlib.sf.net/Matplotlib.pdf

The book you refer to was recently reviewed on slashdot, BTW

  http://books.slashdot.org/article.pl?sid=09/05/27/1327255&from=rss

I've browsed some chapters on Amazon, and it looks well done, but have
not read it myself.

JDH

···

On Thu, Jun 4, 2009 at 6:48 PM, Esmail <ebonak@...32...> wrote:

Hi,

Beginning Python Visualization: Crafting Visual Transformation Scripts
by Shai Vaingast
http://www.amazon.com/Beginning-Python-Visualization-Transformation-Professionals/dp/1430218436/ref=sr_1_1?ie=UTF8&s=books&qid=1244158389&sr=8-1

Has anyone seen/read this book? I am looking for a good
hardcopy reference for matplotlib and associated tools.

While the gallery on the matplotlib site is a good way to learn, I
would like a reference guide that I could easily print out or
a tutorial of sorts, or possibly this book.

John Hunter wrote:

Hi,

Beginning Python Visualization: Crafting Visual Transformation Scripts
by Shai Vaingast
http://www.amazon.com/Beginning-Python-Visualization-Transformation-Professionals/dp/1430218436/ref=sr_1_1?ie=UTF8&s=books&qid=1244158389&sr=8-1

Has anyone seen/read this book? I am looking for a good
hardcopy reference for matplotlib and associated tools.

While the gallery on the matplotlib site is a good way to learn, I
would like a reference guide that I could easily print out or
a tutorial of sorts, or possibly this book.

Hi John,

(sorry for the tardy reply)

Have you tried the official docs? While they are not complete, they do
cover a number of things you mention that you have not seen before
(ion, draw, tutorial, etc.)

  HTML: http://matplotlib.sourceforge.net/users/index.html
  PDF: http://matplotlib.sf.net/Matplotlib.pdf

Thanks for these links, I don't have a problem looking up stuff once
I see it used (like I did once I examined the sample code), but the
problem is unless I see it used, I really don't know that it's available :slight_smile:
I guess looking over the various APIs will help.

The book you refer to was recently reviewed on slashdot, BTW

  http://books.slashdot.org/article.pl?sid=09/05/27/1327255&from=rss

I've browsed some chapters on Amazon, and it looks well done, but have
not read it myself.

I read the ./ review, and there was a post on the general python mailing list
too - it looks promising. I'll have to see if I can find a copy to browse it
myself. I've really been impressed with this software (usually I'm a big fan
of gnuplot).

By the way, any idea how different the MayaVi interface is? I understand that
matplotlib doesn't do 3D plots and I may want to plot some.

Thanks again,
Esmail

···

On Thu, Jun 4, 2009 at 6:48 PM, Esmail <ebonak@...32...> wrote:

Brian Blais wrote:

Someone recently generously shared this code with me on the python

since I was the one to share this with you, I might be able to answer a couple questions. :slight_smile:

Hi Brian,

(sorry for the tardy reply)

I was grateful for the code example, I didn't want to bother you with
more questions.

.. these sort of things I
am curious to learn about before I see them in code for the first
time.

actually, that's how I learned most of it...by seeing it in code at some point. :slight_smile:

Yes, that is very instructive - though a nice narrative/tutorial would
be good too. I'll have to see if I can find a copy of the book locally for
me to look through.

hope this helps,

It sure does, thanks again,

Esmail

···

On Jun 4, 2009, at 19:48 , Esmail wrote:

Esmail wrote:

...
By the way, any idea how different the MayaVi interface is? I understand that
matplotlib doesn't do 3D plots and I may want to plot some.
...

Hey Esmail,

there was the possibility for 3D plots in matplotlib:
http://www.scipy.org/Cookbook/Matplotlib/mplot3D

however, the mayavi "mlab" interface was designed explicitly to be as
simple as pylab.
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html

have fun 3D plotting,
sebastian.

Sebastian Busch wrote:

Hey Esmail,

there was the possibility for 3D plots in matplotlib:
http://www.scipy.org/Cookbook/Matplotlib/mplot3D

however, the mayavi "mlab" interface was designed explicitly to be as
simple as pylab.
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html

have fun 3D plotting,
sebastian.

I'll give mayavi/mlab a try, I think there was a note to the
effect that matplotlib quit supporting 3D plots and recommended
mayavi.

So much to learn, so little time :slight_smile:

Thanks,
Esmail

Sebastian Busch wrote:

Hey Esmail,

there was the possibility for 3D plots in matplotlib:

http://www.scipy.org/Cookbook/Matplotlib/mplot3D

however, the mayavi “mlab” interface was designed explicitly to be as

simple as pylab.

http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html

have fun 3D plotting,

sebastian.

I’ll give mayavi/mlab a try, I think there was a note to the

effect that matplotlib quit supporting 3D plots and recommended

mayavi.

There is still work going on to improve matplotlib 3d plotting
functionality. You can see matplotlib gallery or check-out the latest
trunk of matplotlib and experiment with the 3d examples.

So much to learn, so little time :slight_smile:

Isn’t that nice? Lifelong learning? Why are complaining? Are you not a scientist or raising a kid something :slight_smile:

···

On Tue, Jun 9, 2009 at 12:46 PM, Esmail <ebonak@…32…> wrote:

Thanks,

Esmail

Hi Gökhan,

Gökhan SEVER wrote:

    I'll give mayavi/mlab a try, I think there was a note to the
    effect that matplotlib quit supporting 3D plots and recommended
    mayavi.

There is still work going on to improve matplotlib 3d plotting functionality. You can see matplotlib gallery or check-out the latest trunk of matplotlib and experiment with the 3d examples.

Ah .. ok .. good to know. I was going by this note:

NOTE: 3D plotting has been removed from matplotlib >= 0.98. You'll either need to use an older 0.91.x version or look at Mayavi which is actively maintained and features an 'mlab' interface similar to matplotlib's 'pylab'.

posted here:

http://www.scipy.org/Cookbook/Matplotlib

    So much to learn, so little time :slight_smile:

Isn't that nice? Lifelong learning? Why are complaining? Are you not a scientist or raising a kid something :slight_smile:

hehe .. I know it sounded like a complaint, but it's really not. I
consider myself a lifelong student, and I love learning new things.
I just have a big appetite :slight_smile:

Cheers,
Esmail

Hi Gökhan,

Gökhan SEVER wrote:

I'll give mayavi/mlab a try, I think there was a note to the
effect that matplotlib quit supporting 3D plots and recommended
mayavi.

There is still work going on to improve matplotlib 3d plotting

functionality. You can see matplotlib gallery or check-out the latest

trunk of matplotlib and experiment with the 3d examples.

Ah … ok … good to know. I was going by this note:

NOTE: 3D plotting has been removed from matplotlib >= 0.98. You’ll either need

to use an older 0.91.x version or look at Mayavi which is actively maintained

and features an ‘mlab’ interface similar to matplotlib’s ‘pylab’.

posted here:

http://www.scipy.org/Cookbook/Matplotlib

Modified that section as to eliminate confusions:
NOTE: Experimental work has been going on to integrate 3D plotting functionality into matplotlib. Please see the related mplot3d documentation or take a look at matplotlib gallery for example 3D plots. For a more sophisticated 3D visualization and plotting interface, you can try Mayavi which is actively maintained and features an ‘mlab’ interface similar to matplotlib’s ‘pylab’.

So much to learn, so little time :-)

Isn’t that nice? Lifelong learning? Why are complaining? Are you not a

scientist or raising a kid something :slight_smile:

hehe … I know it sounded like a complaint, but it’s really not. I

consider myself a lifelong student, and I love learning new things.

I just have a big appetite :slight_smile:

No matter how big an appetite you have, you can only digest certain amount of items at a time :slight_smile:
Cheers for lifelong learning :slight_smile:

···

On Tue, Jun 9, 2009 at 1:00 PM, Esmail <ebonak@…32…> wrote:

Cheers,

Esmail