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?

John Howard
  • 61,037
  • 23
  • 50
  • 66
  • 2
    Why do you use Python 3.1? I would stick to 2.6 for the time being. – nikow Jul 30 '10 at 18:49
  • 32
    If everyone thinks that way, 3.1 will never catch on. – John Howard Jul 30 '10 at 18:50
  • it won't catch on if its not backward compatible – amadain Jul 30 '10 at 18:54
  • 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. – nikow Jul 30 '10 at 18:55
  • 4
    Backward compatibility just slows down progress and innovation. – Bertrand Marron Aug 09 '10 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. – mathtick Feb 20 '11 at 23:50
  • @math Did you test without issues? – tshepang Feb 21 '11 at 21:49
  • 1
    I haven't run full tests (is there a 'test' function in the modules?) but am using numpy right now, am creating arrays, matrix multiplying and using the regression tools without issue. – mathtick Feb 21 '11 at 23:51
  • Possible duplicate of [Getting ready to convert from Python 2.x to 3.x](https://stackoverflow.com/questions/3424292/getting-ready-to-convert-from-python-2-x-to-3-x) – gerrit Oct 24 '17 at 16:53

9 Answers9

17

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.

Community
  • 1
  • 1
Duncan
  • 92,073
  • 11
  • 122
  • 156
11

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

tshepang
  • 12,111
  • 21
  • 91
  • 136
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
  • 5
    I would say _a lot_ of progress :) (it's been working fine for me) https://github.com/matplotlib/matplotlib-py3 (I know this thread is old -- but ranks high on results for "matplotlib python3" in google) – mgalgs Jun 14 '11 at 17:22
  • I get lame exceptions when trying to save figures. – Matt Joiner Nov 09 '11 at 00:24
  • A version for Python3.3 is available at their [official page](http://matplotlib.org/downloads.html) – Aseem Bansal Aug 22 '13 at 16:05
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()
N0thing
  • 6,745
  • 3
  • 20
  • 16
  • 1
    Where is the URL API documented? – Matt Joiner Nov 09 '11 at 00:25
  • Charts URL API tutorial: http://psychopyko.com/tutorial/how-to-use-google-charts/ Reference now says "deprecated": http://developers.google.com/chart/image/docs/chart_params Charts API, main page: http://developers.google.com/chart/ Charts API ref seems to be all Javascript now: http://developers.google.com/chart/interactive/docs/reference Gallery of examples: http://google-developers.appspot.com/chart/interactive/docs/gallery Linechart example, "view source": http://google-developers.appspot.com/chart/interactive/docs/gallery/linechart Also: http://en.wikipedia.org/wiki/Google_Chart_API – Dave Burton Jul 22 '12 at 13:17
1

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

Marina
  • 11
  • 1
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/

tshepang
  • 12,111
  • 21
  • 91
  • 136
Andrew
  • 12,821
  • 2
  • 26
  • 18
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.

ChrisC
  • 1,282
  • 9
  • 9
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

lgautier
  • 11,363
  • 29
  • 42
1

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

abalakin
  • 825
  • 7
  • 6
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

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67