130

What are the available libraries for creating pretty charts and graphs in a Python application?

sverrejoh
  • 16,464
  • 13
  • 41
  • 29
  • 22
    I'm not sure why this one got closed. It doesn't invite flame wars or opinions, and has a set of clear answers: there are only a handful of Python plotting libraries. – Alex B May 12 '12 at 12:57
  • 7
    Why is this closed? This is a useful question. Anyway, my recommendation is to `pip search plot` and look at what comes up. I discovered pygal by doing this, and pygal looks great. – Mark E. Haase Jul 25 '12 at 23:53
  • Also worth noting that this question comes up top of a google search for "charting python" -- reason enough to open it again. – George Lund Oct 16 '13 at 12:23
  • This question is useful, it should not be closed. Other options include [bokeh](https://github.com/ContinuumIO/Bokeh) and [PyX](http://pyx.sourceforge.net/) – Lee Oct 17 '13 at 12:48

15 Answers15

50

I'm the one supporting CairoPlot and I'm very proud it came up here. Surely matplotlib is great, but I believe CairoPlot is better looking. So, for presentations and websites, it's a very good choice.

Today I released version 1.1. If interested, check it out at CairoPlot v1.1

EDIT: After a long and cold winter, CairoPlot is being developed again. Check out the new version on GitHub.

Tundebabzy
  • 829
  • 2
  • 11
  • 24
Rodrigo
  • 5,938
  • 6
  • 31
  • 39
  • 2
    Looks good, I'd like to try it. Any plan to make a windows installer for python 2.6? – monkut Oct 22 '08 at 05:03
  • No problem for the support, as I agree on it. Thanks for the compliment :D – Rodrigo Feb 06 '09 at 11:00
  • Just added http://stackoverflow.com/questions/359727#520049 for you to downvote, if you want. – VonC Feb 06 '09 at 12:06
  • 1
    Cairoplot really doesn't work that well for large amounts of data though (correct me if I'm wrong). You can't add labels to the axis to summarise the hlabels or vlabels. I can't see anyway to plot multiple lines on a graph or have any control over the colours used. I could hack away at the script... moving to matplotlib... – Jonathan Holloway Oct 30 '09 at 20:40
  • Everyone should disregard Jon's comment, its very easy to label axis and define the colors used...Check tests.py for examples. Anyways, Thanks for a nice lib. – Daniel Magnusson Nov 13 '09 at 08:05
  • gantt_chart() doesn't work for this data set any idea ? tg_p = [ (0, 12), (0, 5), (0,13) ] tg_v = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'] tg_h = [ 'test', 'test2', 'test3' ] tg_c = [ (1.0, 0.0, 0.0), (1.0, 0.7, 0.0), (0.0, 1.0, 0.0) ] CairoPlot.gantt_chart('gantt-123', tg_p, 600, 300, tg_h, tg_v, tg_c) – m1k3y3 Nov 11 '10 at 12:35
38

For interactive work, Matplotlib is the mature standard. It provides an OO-style API as well as a Matlab-style interactive API.

Chaco is a more modern plotting library from the folks at Enthought. It uses Enthought's Kiva vector drawing library and currently works only with Wx and Qt with OpenGL on the way (Matplotlib has backends for Tk, Qt, Wx, Cocoa, and many image types such as PDF, EPS, PNG, etc.). The main advantages of Chaco are its speed relative to Matplotlib and its integration with Enthought's Traits API for interactive applications.

Barry Wark
  • 107,306
  • 24
  • 181
  • 206
  • 2
    I agree that of all the APIs - matplotlib seems to be indeed the most mature and feature-rich (and also is still supported and being further developed). Just go to its "gallery" to see various examples (with according source code): http://matplotlib.sourceforge.net/gallery.html. However, I'd say that its API is, well..., complicated - method names are driving me crazy :) Speaking about "complicated" and simple examples - this blog post helped me a lot to start with matplotlib: http://shreevatsa.wordpress.com/2010/03/07/matplotlib-tutorial/ – Tim Apr 12 '12 at 20:15
  • Sorry, I have to add also, that matplotlib is not only interactive - you can actually save plot/chart to a file. For ex. PNG, PDF or SVG. – Tim Apr 12 '12 at 20:25
18

You can also use pygooglechart, which uses the Google Chart API. This isn't something you'd always want to use, but if you want a small number of good, simple, charts, and are always online, and especially if you're displaying in a browser anyway, it's a good choice.

Tony Meyer
  • 10,079
  • 6
  • 41
  • 47
  • 7
    A word of warning, the charts that Google allows you to create are rather limited in size (width * height <= 300,000 pixels). Also, Google Charts (not the Python API) will choke with even modestly sized data sets. Otherwise, they're great. – Pat Notz Sep 17 '08 at 04:18
  • 1
    Google Image Charts are still available, but deprecated. For more info, go to https://developers.google.com/chart/image/?hl=nl – ndequeker Nov 02 '12 at 15:58
15

You didn't mention what output format you need but reportlab is good at creating charts both in pdf and bitmap (e.g. png) format.

Here is a simple example of a barchart in png and pdf format:

from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart

d = Drawing(300, 200)

chart = VerticalBarChart()
chart.width = 260
chart.height = 160
chart.x = 20
chart.y = 20
chart.data = [[1,2], [3,4]]
chart.categoryAxis.categoryNames = ['foo', 'bar']
chart.valueAxis.valueMin = 0

d.add(chart)
d.save(fnRoot='test', formats=['png', 'pdf'])

alt text http://i40.tinypic.com/2j677tl.jpg

Note: the image has been converted to jpg by the image host.

serbaut
  • 5,852
  • 2
  • 28
  • 32
  • 2
    If get an exception "RenderPMError: Can't setFont(Times-Roman) missing the T1 files?" (like I got) on d.save in above code - Solution is to download and extract http://www.reportlab.org/ftp/fonts/pfbfer.zip in reportlabs/fornts directory – Shekhar Nov 30 '09 at 11:54
  • +1 for the effort of generating a practical example. – vmassuchetto Sep 16 '11 at 19:52
6

I used pychart and thought it was very straightforward.

http://home.gna.org/pychart/

It's all native python and does not have a busload of dependencies. I'm sure matplotlib is lovely but I'd be downloading and installing for days and I just want one measley bar chart!

It doesn't seem to have been updated in a few years but hey it works!

tullaman
  • 176
  • 2
  • 8
6

CairoPlot

elmarco
  • 31,633
  • 21
  • 64
  • 68
  • 2
    Why is it good? Have you used it? – Nick Nov 10 '09 at 10:24
  • Yes, I used dot_line_plot() in reporting/stats tools. It's pretty and easy. See the top reponse from Rodrigo about Matplotlib and CairoPlot. I also use Matplotlib. In fact, I am using it right now. – elmarco Nov 10 '09 at 10:47
  • Strange people haven't caught your answer, but the currently top voted answer. – pihentagy Feb 07 '12 at 13:47
  • I think this would get more upvotes if there was a minimal example. Your answer will get useless when the link is dead. – Martin Thoma Apr 07 '13 at 08:40
  • thanks, the blog has a lot of informations already. and the author himself answered here with more details later. – elmarco Apr 08 '13 at 01:36
4

If you like to use gnuplot for plotting, you should consider Gnuplot.py. It provides an object-oriented interface to gnuplot, and also allows you to pass commands directly to gnuplot. Unfortunately, it is no longer being actively developed.

mhagger
  • 2,687
  • 18
  • 13
4

Have you looked into ChartDirector for Python?

I can't speak about this one, but I've used ChartDirector for PHP and it's pretty good.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
4

NodeBox is awesome for raw graphics creation.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
3

You should also consider PyCha http://www.lorenzogil.com/projects/pycha/

Mayowa
  • 196
  • 1
  • 5
3

Chaco from enthought is another option

Azim J
  • 8,260
  • 7
  • 38
  • 61
3

I am a fan on PyOFC2 : http://btbytes.github.com/pyofc2/

It just just a package that makes it easy to generate the JSON data needed for Open Flash Charts 2, which are very beautiful. Check out the examples on the link above.

Gourneau
  • 12,660
  • 8
  • 42
  • 42
1

Please look at the Open Flash Chart embedding for WHIFF http://aaron.oirt.rutgers.edu/myapp/docs/W1100_1600.openFlashCharts and the amCharts embedding for WHIFF too http://aaron.oirt.rutgers.edu/myapp/amcharts/doc. Thanks.

Aaron Watters
  • 2,784
  • 3
  • 23
  • 37
0

PLplot is a cross-platform software package for creating scientific plots. They aren't very pretty (eye catching), but they look good enough. Have a look at some examples (both source code and pictures).

The PLplot core library can be used to create standard x-y plots, semi-log plots, log-log plots, contour plots, 3D surface plots, mesh plots, bar charts and pie charts. It runs on Windows (2000, XP and Vista), Linux, Mac OS X, and other Unices.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
0

You could also consider google charts.

Not technically a python API, but you can use it from python, it's reasonably fast to code for, and the results tend to look nice. If you happen to be using your plots online, then this would be an even better solution.

Tyler
  • 28,498
  • 11
  • 90
  • 106