views:

4764

answers:

15

What Python plotting library do you recommend?

It should be noted the following considerations:

  • is it cross-OS?
  • speed
  • how clean it's interface?
  • "prettyness" of the resulting plots
  • License
  • etc?

In the Python Wiki there is a list, but there is little comparison between them.


Interesting SO links (not quite duplicates, but usefull to someone comming to this question):

+15  A: 

If you've ever used MATLAB, check out MatPlotLib. The code syntax & plots generated are very similar to MATLAB. You can easily make publication-quality plots with minimal effort.

Pete
That looks pretty "Spiffy." What about a more raw drawing package? Something simalar to the drawing methods most GUIs have for a canvas type element, but without requiring all the window setup BS. I've always been annoyed by all the extra crap you have to do in WinDoze to get to the point you could actually draw pixels.
NoMoreZealots
Maybe I'm misunderstanding you, but MatPlotLib can be driven directly from the command-line and output PNG's, TIFF's, etc. without "all the windows setup BS" with minimal lines of code.
Pete
I gess what Pete is looking for is something more on the lines of mail.python.org/pipermail/python-list/2000-December/061954.html or http://www.linuxquestions.org/questions/programming-9/draw-a-pixel-with-python-626513/
voyager
A: 

I've used matplotlib with excellent results.

Macarse
+1  A: 

My coworker successfully used matplotlib for his entire master thesis (psychology). He's recommended this library to me as well, though I only used it briefly.

Dana the Sane
A: 

I used pygooglechart, as it produced pretty charts with no extra work in prettyfication, while the others usually created butt ugly charts unless you put down an effort in choosing the right fonts and colors, etc.

Lennart Regebro
+7  A: 

I have been using matplotlib for my plotting, and have been extremely pleased thus far. In addition to creating plots that just plain look nice, there are several features I find compelling:

  • The gallery gives a listing of many different plots that can be generated, along with the code that generated the plot. Whenever I'm trying something new, I'll skim through there to see if an example already exists.
  • The basemap package may not be useful for everyone, but just about everything we do involves some sort of geo-referencing. It's great to be able to switch map projections, regions, etc. with minimal code.
  • It plays well with other packages, producing output in may different formats. I've used it with Django as well to render custom plots directly into the HTTP response.

I've found most of the documentation very helpful, and it seems to be under active development. Combine it with IPython and you have yourself an excellent environment for both interactive data analysis and also publication-quality graphics.

As mentioned, it includes a pylab mode where the plotting commands are similar to MATLAB. I've found this helpful in getting started, but being able to explore a little deeper and deal with the OO interface has been useful as well.

Edit: Since you asked about cross-platform, I've used this package personally on an IBM Power6 (running AIX), a Cray XT5, and Linux and Windows machines. Although I haven't used it personally, OS X is also supported.

Tim Whitcomb
Many interesting points. I guess this is as close as I'll get for what I need (bar graphs and point plots). The basemap package looks promising, somehow I missed it.
voyager
+1  A: 

It depends on what you mean by "plotting" (some people could write entire dissertations on the differences between plots and charts). If you want really nice looking "charts", which can function as scientifically useful "plots" in most cases, you should take a look at ChartDirector. It has wrappers for Python/C/C++/Java/Ruby/Perl/etc., supports internationalization, is fast, and has a pretty reasonable API (runs on at least Solaris, Windows, Linux, and MacOS X).

One note would be that it is non-free ($99), but imo presents the best looking graphics (full anti-aliasing, etc.) of any available package. There is a free trial available so you can get a feel for it before handing over any cash.

Nick Bastin
+2  A: 

If you are interested in Interactive plots with linked zooming/panning there is the Chaco library. A part of the Enthought Tool Suite

pdemarest
My issue with Enthought's tools is speed.
Matt
+2  A: 

I've recently wondered about this as well, trying to compare Matplotlib with PyQwt for my own uses. Here's the summary, you may find it useful.

Eli Bendersky
+2  A: 

I generally use matplotlib, mostly for reasons already mentioned by other answers. But I've been using CairoPlot lately when I need something quick and pretty because the defaults work out nicely. With matplotlib, I have to tweak things a little bit every time.

ars
So what you are saying is that CairoPlot is easier to work with compared to matplotlib? But given more time/tweaks, does matplotlib looks better than CairoPlot?
voyager
Those are pretty plots. Thanks for pointing this out. There aren't many examples though, so can you tell more about it. For example, how well does this work for large data sets, like 10K points?
tom10
@voyager: Right, matplotlib can be tweaked to produce as good or better charts. @tom10: Sorry, I've never put CairoPlot through its paces with large datasets.
ars
+2  A: 

CairoPlot produces very pretty plots (it uses gradients and pleasing colours by default), but it's not a full featured as matplotlib. So if you're looking for features, matplotlib is probably the way to go, but if you're looking for pretty charts (for UIs, etc.), I'd take a look at CairoPlot as see if it has what you need.

Aaron Maenpaa
+3  A: 

I'll join everyone else in recommending matplotlib but the best feature in my mind is the support for LaTeX. The syntax is really natural as long as you remember to use raw strings:

xlabel(r"$\frac{x^2}{y^4}$")

I think you need to set text.markup = "tex" in your matplotlibrc configuration file for this to work.

If you want every piece of text in the graph to be LaTeX'd including the axis tick labels you can set text.usetex = True in matplotlibrc. This is great for making your graph have the same look as the rest of your paper when using LaTeX.

ihuston
+1. It would also be great for displaying funtions directly in the graph. Thank's for pointing this up! This will definetly be useful.
voyager
A: 

I found MatPlotLib to be an enormous headache to install and use cross-platform. Not being able to generate 3D plots (even static/non-interactive ones) was the last straw, so I quickly dropped MatPlotLib. My go-to for plotting from Python has since become gnuplot, which has a very nice, simple Python wrapper called Gnuplot.py. If you can do it in gnuplot, you can pretty much do it in Python with Gnuplot.py.

Matt Ball
Matplotlib has 3D support through its mplot3d toolkit, which is installed but must be imported separately.
doug
At the time (first half of 2009 or so) it was not officially supported - the latest version was 0.98. http://www.scipy.org/Cookbook/Matplotlib/mplot3D.
Matt Ball
+1  A: 

For 3D plotting, in terms of power in speed, Mayavi2 offers probably the best tradeoff as it is very powerful and versatile on big dataset.

It is also however a big dependency.

Gael Varoquaux
A: 

gplot is a very simple Gnuplot in Python. check it at pyla.codeplex.com

atronoush
+1  A: 

also http://root.cern.ch/drupal/image is quite good (mainly used in particle physics, but aplicable everywhere) Also it ships with LOTS of advanced statistical stuff from simple fitting to MVA. OpenGL support included. CHeers, MadMUd

MadMud