Beginning Python Visualization 46
aceydacey writes "Sometimes a picture is worth a thousand words. Beginning Python Visualization: Creating Visual Transformation Scripts, published in February 2009 by Apress, shows how Python and its related tools can be used to easily and effectively turn raw data into visual representations that communicate effectively. The author is Shai Vaingast, a professional engineer and engineering manager who needed to train scientists and engineers to do this kind of programming work. He was looking for a tutorial and reference work, and unable to find a suitable text, wound up writing his first book. He writes in the easy and clear style of someone comfortable and engaged with the subject matter." Keep reading for the rest of aceydacey's review.
The book uses several very specific examples that illustrate general principles.
Beginning Python Visualization: Crafting Visual Transformation Scripts | |
author | Shai Vaingast |
pages | 363 |
publisher | Apress |
rating | 9/10 |
reviewer | aceydacey |
ISBN | 1430218436 |
summary | learn how to process, organize, and visualize data from various sources using the Python language |
The first example is using GPS data. By using Python one can extract data from GPS receivers and enter it into the computer and manipulate it to do what one wants including creating graphs and charts. In this section he shows how to use CSV, comma separated values, as a most useful file format. He shows show to extract data from real world GPS devices and import it via serial ports and the PySerial module. It would be easy for the reader to duplicate and extend this project.
The heart of the book is coverage of useful examples utilizing MatPlotLib, NumPy and SciPy. These related tools are easy to use and fully integrated with Python. MatPlotLib is for plotting data and graphs, including interactive graphs and image files. NumPy is a powerful math library comparable to commercial tools like MatLab, and SciPy extends NumPy to for the sciences. Examples are numerous and include signal analysis using Fourier transforms.
There is also a section on Image Processing using PIL, the Python Imaging Library. This is used for relatively simple image cropping and sizing and also for bit by bit image processing. Interpolation and curve fitting are also well covered. For anyone wanting an introduction to graphical analysis of statistical data, this would be an excellent resource.
The author is obviously a professional in this field. He has a knack for good organizational style and a pragmatic approach to the work. In the book he says "Most of the time, research is organized chaos. The emphasis, however, should be on organized, not chaos." A real value I got from the book is a better understanding of data files, format, and organization as well as methods and guidelines for selecting file formats and storing and organizing data to enable fast and efficient data processing. It is obvious that this book was written by a practicing engineer.
The theme of the book is that Python can be an all purpose environment for data manipulation and visualization, using nothing but free and open source tools that are easily integrated and scriptable without using multiple programming languages. The book should be an invaluable tool for scientists and engineers but it is also easily accessible to anyone interested in math and data analysis. There is no need for an advanced math background. While, as a matter of full disclosure, I have undergraduate degrees in Math and Physics, I feel the book should be easily accessible to anyone with a solid high school math background who is seriously interested in the subject. The book contains a short introductory tutorial on the basics of Python so anyone familiar with programming in any language should be fine.
The book is an easy read from front to back, and I am sure it will also be a good reference resource for the future. The writing style is very clear and unforced and I found surprisingly few errors. While the Python world has a surplus of introductory and general books, books covering this kind of specific domain are especially welcome, and we could use more on other topics by competent authors.
At 363 pages the book is a surprisingly fast read. Its methodology is to use specific, short code examples to make all the key points. Most of the code samples are well selected, short and written in clear, concise Python. This is not the kind of book that overwhelms you with massive amounts of code. Either the book was well edited or else it was written by an exceptionally lucid thinker, or both.
So, if you want to learn how to process, organize, and visualize data from various sources using the Python language, I recommend this book to you. I have also posted a podcast of an interview with the author at Python411
You can purchase Beginning Python Visualization: Crafting Visual Transformation Scripts from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Re:really? (Score:5, Informative)
are book reviews news?
If you use the classic index, click here [slashdot.org] and select the no smoking column for book reviews. If you use the dynamic index, click here [slashdot.org]. In this view, find Exclusions under the dynamic index and click it. In the box for other terms, enter "book review" with the quotes and save it the page. Upon a page refresh of your home page, you should notice no more reviews of books.
Re: (Score:2)
Getting up and running (Score:5, Informative)
A great way to set yourself up with a Python-based analysis environment is a tool amalgamation called Python(x,y) [pythonxy.com]. I don't use it myself since my setup predates the project, but it has all the major tools I know and love.
And for those of you who want statistical and graphing capabilities lacking there, know that you can communicate back and forth with an instance of GNU R, using rpy2 [sourceforge.net].
Re: (Score:2, Informative)
All of these libraries are also include in Enthought's python distribution called EPD [enthought.com]. While it is a commercial product, it is free for commercial use and there is also a 30-day free trial for anyone. EPD is available on platforms Python(x,y) doesn't cover.
Re:Getting up and running (Score:5, Informative)
Sage (http://www.sagemath.org) is also includes numpy, scipy, matplotlib, R, and many, many other packages. All of these are easily usable from a command line interface as well as an easy web interface (see http://www.sagenb.org)
Mayavi should also be mentioned when talking about python and visualization: http://code.enthought.com/projects/mayavi/
You can use Mayavi and Sage together as well. Here's a link to a public Sage worksheet illustrating how to use Mayavi to generate a 3d VRML interactive image embedded in the page: http://nb.hpfem.org/home/pub/16/ (install a X3D viewer like FreeWRL to see the last interactive image). Sage also does 3d graphing with JMOL.
Comment removed (Score:5, Funny)
Re: (Score:2)
I can quote it for you now and make you R-O-T-F-L-O-L
Re: (Score:1, Funny)
import tk? (Score:2, Informative)
import tk
and that's not correct at all, if you're among these people, you should read this book... good luck!
Processing / "Visualizing Data" (Score:4, Interesting)
Ben Fry's Visualizing Data [amazon.com] using the Processing [processing.org] environment seems like it's addressing a similar topic... wonder if Vaingast didn't know about it or if he found something unsuitable about it...
Re: (Score:3, Informative)
There is also The Visualization Handbook [amazon.com] which covers all the different classifications of data and the appropriate techniques to visualise. Lots of theory and algorithms under the hood.
Re: (Score:3, Interesting)
In our lab (@ Georgia Tech), we developed an processing port to python that uses pygame + OpenGL as the base.
We haven't open-sourced it yet, but do think people would find that interesting?
Re: (Score:2, Interesting)
Re: (Score:1)
Re: (Score:3, Interesting)
On the other hand, there's a GPL fork/port of this project that works on GNU/Linux and Windows -- Shoebot (http://www.tinkerhouse.net/shoebot [tinkerhouse.net]) (Disclosure: i'm one of the authors)
Nodebox uses Cocoa as its graphics back-end, while Shoebot uses Cairo (http://www.cairographics.org/ [cairographics.org]); our plans for it are to implement other graphics back-ends including OpenGL (via Pyg
Python to visualize in a virtual world (Score:3, Interesting)
Viz without interaction? (Score:3, Interesting)
Review FAIL (Score:2)
"Sometimes a picture is worth a thousand words". And then we get a review with no pictures. Just links to other stuff. And a link to an audio file - sorry, I mean 'PodCast' - which also won't have any pictures, or text I can search, or examples I can cut n paste.
It's like a review of Playboy without at least one carefully cropped picture, coupled with a taped interview with one of the bunnies.
I like matplotlib, scipy but ... (Score:2)
Re: (Score:1)
You don't mention ipython, but I had a very similar problem making and closing plots when using ipython, but not when using straight python for the interactive session (or, obviously, in scripts). The problem is that ipython caches things it really shouldn't, like closed plots. Try setting the ipython "-cs" option to 0 and see if things improve.
Fail already (Score:3, Interesting)
Useful? Not in an international environment. English CSV uses commas as the name implies, but export a .csv from French excel and it uses semicolons.
I hate CSVs. Mr noob author, may I introduce my good friend Mr tab?
Re: (Score:2, Informative)
Disclaimer: I know the author
Re: (Score:2)
(what's the opposite of n00b anyway?)
u can use l33t, 1337, 0r 3v3n 001011011111, but tehn again, how would u kn0w, suxxor?
the opposite of n00b (Score:2)
1337
Re: (Score:1)
The book is about Python so it probably isn't that out of place that there is reasonable support for csv files included in the standard install:
http://docs.python.org/library/csv.html [python.org]
No support for Unicode (yet) would probably be the biggest caveat. I've had good luck with it, but I haven't exercised it in particularly interesting ways.
Re: (Score:2)
I was guessing that although there is nothing even remotely new about a .csv file, our reviewer mentions this as an example of good style. You could write data out in any format you invent for each project, and with Python you might be particularly tempted to use some pickle (Python's object serialization) format. But using CSV whenever it makes any sense seems like it would give you the most long-term flexibility since so very many programs can read these files, even text editors. The format is never go
Re: (Score:3, Funny)
Your thinking has you almost to understanding why XML was invented.
The one, only true serial file format that will rule them all.
Learn to use an XML tool set and never deal with reading or writing data issues again.
Why is XML better then CSV (I remember asking this)? It's hierarchical right in the spec.
Sure you can make a hierarchical CSV file. But yours will be special. Not so with XML.
Re: (Score:2)
Fair point. But what about csv files that are > 2TB each in size that describe integers, floats and unsigned shorts? XML will increase this size by what factor? An order of magnitude?
For small files ... absolutely.
Commas Suck (Score:3, Informative)
Yes, I know commas are part of the CSV acronym but seriously they suck. A lot of the data I've worked with over the years (names, addresses, etc) was usually bound to have some records with embedded commas in the field values thus generating import exceptions.
I learned early on to use tabs for any CSV exports I had to create. And Excel has no problem interpreting tab-delimited files.
Re: (Score:2)
if semicolons instead of commas in a CSV file are the biggest problem you've run across with CSVs, you haven't lived.
Now get off my lawn.
CairoPlot (Score:2, Informative)
There's a fairly new project called Cairoplot [launchpad.net] that creates charts and plots using Python and Cairo. It's not meant to do number-crunching like some of the other tools mentioned, but it creates great-looking charts.
(Disclaimer: I've done a little bit of development on Cairoplot, trying to get it more LaTeX-friendly)
IT Infrastructure Viz w/ Python (Score:1)
3D Visualization (Score:3, Interesting)
Re: (Score:1)
Great Book (Score:1)
Google Earth (Score:2)
If you have geographic data, Google Earth is a great output viewer. It is easy to use Python to write a KML [google.com] file.
matplotlib (Score:1)