16

In Python 2.6, I used matplotlib to make some simple graphs. However, it is incompatible with Python 3.1.

What are some alternative modules that can accomplish the same thing without being very complex?

9
  • 2
    Why do you use Python 3.1? I would stick to 2.6 for the time being. Commented Jul 30, 2010 at 18:49
  • 32
    If everyone thinks that way, 3.1 will never catch on. Commented Jul 30, 2010 at 18:50
  • 6
    Of course it will catch on, Numpy just gained compatibility, now others will follow. If you want to help then maybe try to contribute to the matplotlib porting effort. Commented Jul 30, 2010 at 18:55
  • 4
    Backward compatibility just slows down progress and innovation. Commented Aug 9, 2010 at 15:08
  • 2
    In case someone comes across this post ... I've just installed numpy and scipy in python 3.1.2 without problem. Commented Feb 20, 2011 at 23:50

9 Answers 9

17
+25

You say you want to create some simple graphs but haven't really said how simple or what sort of graphs you want. So long as they aren't too complex you might want to consider using the Google Chart API.

e.g. an example chart

That has some advantages: you just have to construct a URL that describes the desired chart so there shouldn't be any issues using it from Python 3.x. Of course there are disadvantages also: you need to have an internet connection when generating the chart, and you might not have the chart styles you have been using with matplotlib.

If you don't want to construct the URLs directly there is at least one Python wrapper for the charts API. It doesn't work directly on Python 3.x, but running it through 2to3 seems to convert it successfully.

Sign up to request clarification or add additional context in comments.

3 Comments

Where is the URL API documented?
@MattJoiner, it looks as though Google have updated their chart API so now the docs mostly talk about the new visualization classes. Try code.google.com/apis/chart/image/docs/making_charts.html for the URL API.
would the downvoter like to leave a comment saying why? Thanks
11

A stable version supporting Python 3 has since been released: official announcement.

3 Comments

I would say a lot of progress :) (it's been working fine for me) github.com/matplotlib/matplotlib-py3 (I know this thread is old -- but ranks high on results for "matplotlib python3" in google)
I get lame exceptions when trying to save figures.
A version for Python3.3 is available at their official page
3

I wrote a small example that runs in python 3 and uses the google chart api (as suggested by Duncan, I wrote the solution after seeing this post).

It is not ideal since it adds a dependency one a 3rd party that might break backward compatibility at any time, but the graphs are nice and there is absolutely no added dependency on the python code. Worth considering for not 'mission critical code'.

You can find/download the example here. Here is the graph that it generates from data in a .xml file: alt text

# build the query with template parameters
query ="http://chart.apis.google.com/chart?chxl=0:__X_LABELS__&chxp=__X_LABELS_POS__&chxr=0,__MIN_TIME__,__MAX_TIME__|1,__MIN_WEIGHT__,__MAX_WEIGHT__&chxs=0,676767,11.5,0,lt,676767|1,676767,11.5,0,lt,676767&chxt=x,y&chs=800x300&cht=lc&chco=3072F3&chds=__MIN_WEIGHT__,__MAX_WEIGHT__&chd=t:__COMMASEP_WEIGHT__&chdl=Weight&chdlp=b&chls=2,4,1&chma=5,5,5,25&chtt=Your+Weight+Timeline"

[...]

# relace template with data
query = query.replace('__X_LABELS__', strXLabels)
query = query.replace('__X_LABELS_POS__', strXLabelsPos)
query = query.replace('__MIN_TIME__', str(min(lst_dateEpoch)))
query = query.replace('__MAX_TIME__', str(max(lst_dateEpoch)))

[...]

# use 'urllib.request' to download the data & write to file
sock = urllib.request.urlopen(query)
image_bytes = sock.read()
sock.close()

fh = open('Weight_GoogleGraphApi.png', 'wb')
fh.write(image_bytes)
fh.close()

2 Comments

Where is the URL API documented?
1

Maybe PyQwt? They claim 3.x compatibility. I've only used Qwt (the C++ lib PyQwt is based on) but I found it fairly useful.

Comments

1

rpy2 is providing access to the graphics capabilities of R, and rpy2 is becoming compatible with Python 3 (thanks to the help of Google for funding Greg over the summer).

Code against the current dev branch is in a patch queue.

edit: rpy2 2.2.0 is working with Python 3.2

Comments

1

MathGL (GPL plotting library) have Python interface which work with Python 3 too.

Comments

1

Matplotlib binaries for python 3.x (windows) are avaliable. http://www.lfd.uci.edu/~gohlke/pythonlibs/

1 Comment

Is this some sort of alpha/beta?
1

As an alternative to installing subversion to grab the source, Numpy's SF files page has the latest copy of 1.5 in a few different (Windows-friendly) formats:

http://sourceforge.net/projects/numpy/files/NumPy/1.5.0b1/

Comments

0

There are at least two graphing libraries using PyQt, namely PyQwt and PyQtGraph. I've been using PyQwt with Python 2.6 for a few weeks now and it is quite handy. The documentation isn't great, and most of the time I need to refer to either the Qwt docs or the examples - although the times I've had to look at the docs have been few and far between, it is VERY easy to use. I tried building it against python 3.1 just now though without success. I coulnd't find the tar package for 5.2.1 which is the only version compatible with python 3.0 and there isn't anything on MacPorts for that either.

There is also a fairly complete looking list of plotting libraries on at python.org http://wiki.python.org/moin/NumericAndScientific/Plotting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.