Dynamically Generating a Graph in Python

T

Tim Henderson

Hi
I want to dynamically generate a graph in python that would be
displayable on a web page. What would be the best way to do this?

The reason I want to do this, is because I am making a program to
convert data from scientic probes into web pages. I have been able to
do every thing except the graph generation.

Your help would be much appriciated
 
I

Istvan Albert

Tim said:
I want to dynamically generate a graph in python that would be
displayable on a web page. What would be the best way to do this?

See if you can run graphviz in the background.

http://www.research.att.com/sw/tools/graphviz/

If yes you'll need to create an input file
based on your data then run the dot utility
on it to generate a graphics file.

There is pydot module that generates graphviz
files:

http://dkbza.org/pydot.html

IMO is a little bit too complicated, and might not be worth the trouble.

The dot file format is fairly simple and you might be better off
just understanding it and then generating directly
in that format. You will need to understand the format
anyhow if you want to customize the output.

Istvan.
 
G

Grant Edwards

I want to dynamically generate a graph in python that would be
displayable on a web page. What would be the best way to do this?

I'd use gnuplot-py:

http://gnuplot-py.sourceforge.net/
The reason I want to do this, is because I am making a program
to convert data from scientic probes into web pages. I have
been able to do every thing except the graph generation.

gnuplot can generate a huge number of different file formats,
including png, svg, eps, pdf, ppm, gif, and so on.
 
F

Fernando Perez

Ivan said:
If this is indeed what he means:) I began to use PyChart last week:

http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/

I is o.k. for relatively simple statistical charts, and may produce output in
SVG, PS, PDF, PNG, and interactive X11 display

With all due respect for the author of this tool, I have a really hard time with
comments like this on his page:

Gnuplot.
A long-time favorite of researchers. But its output is not up to publishing
standard, in my opinion.

Gnuplot has been around for many years (I've used it since 1991), and its
postscript is extremely good. Definitely far better than any of the examples
shown in the pychart page, all of which have that god-awful look of Excel cheap
charts.

In python, for the last few years I've been using (yes, for real research)
gnuplot with much success (with Gnuplot.py and the enhancements which ipython
ads), and right now I'm in the process of switching to matplotlib (and doing
much work so that ipython supports matplotlib for interactive work).

IMHO, matplotlib has a very clean design which makes it a great tool to bet on
for the future, with very good functionality, high quality output, and is being
actively developed by a strong team (not just John Hunter, but also the good
folks from the Hubble Space Telescope Science Institute).

Just my $.02,

f
 
F

Fernando Perez

Fernando said:
being actively developed by a strong team (not just John Hunter, but also the
good folks from the Hubble Space Telescope Science Institute).

Just to clarify the above. John is a great coder, but he is obviously busy and
his professional research also demands much of his time beyond matplotlib. The
point I was trying to make is that matplotlib is not a one-man effort.
Instead, it has the support of a strong team of scientists who use it in a real
production environment.

Best,

f
 
I

Ivan Herman

You put me in a strange situation... it is not my goal to compare gnuplot and pychart, I
am just a messenger... I am not even sure that the two are comparable, to be fair (to both).

Pychart (as far as I am concerned) is a small and lean package to do statistical charts
and nothing else. Gnuplot is *much* more than that, it is more powerful and, consequently,
complex. Personally, my problem with gnuplot was that it lacked, for example, any
pie-chart facility (it is a topic of debates on the relevant mailing lists, b.t.w.) and I
was simply too lazy;-) to do start learning gnuplot and do it myself. In any case: I am
afraid we are comparing apples and oranges here.

As for the remark of the author you quote below... I let him defend himself if he reads
these lines. Personally, I do not care about it.

Ivan
 
I

Ivan Herman

You put me in a strange situation... it is not my goal to compare gnuplot and pychart, I
am just a messenger... I am not even sure that the two are comparable, to be fair (to both).

Pychart (as far as I am concerned) is a small and lean package to do statistical charts
and nothing else. Gnuplot is *much* more than that, it is more powerful and, consequently,
complex. Personally, my problem with gnuplot was that it lacked, for example, any
pie-chart facility (it is a topic of debates on the relevant mailing lists, b.t.w.) and I
was simply too lazy;-) to do start learning gnuplot and do it myself. In any case: I am
afraid we are comparing apples and oranges here.

As for the remark of the author you quote below... I let him defend himself if he reads
these lines. Personally, I do not care about it.

Ivan
 
H

HansWL

John Hunter said:
gdmodule is really more of a low level drawing program than a graphing
module. Of course you can draw graphs with it, as you can with any
drawing program, but it's a lot easier to make scientific graphs (the
OP's interest) with a program designed for that purpose. matplotlib
has a gdmodule backend.

http://matplotlib.sourceforge.net/backends.html#GD

JDH

I tried matplotlib 0.63 with Python 2.3.4 on an old Win98 machine (500
MHz, 128 MB RAM) and found that I had to wait for at least 35 seconds
before even the simplest demo plot appeared. Is this expected?

The plots looked great, I just hope they appeared faster.
 
J

John Hunter

HansWL> I tried matplotlib 0.63 with Python 2.3.4 on an old Win98
HansWL> machine (500 MHz, 128 MB RAM) and found that I had to wait
HansWL> for at least 35 seconds before even the simplest demo plot
HansWL> appeared. Is this expected?

No it is not expected. My guess is that something may be wrong with
your configuration. While I don't have anything as clunky as your
machine to test on <wink>, I do have python 2.3.4 with the same
matplotlib on a 700MHz win98 box with 512 MB RAM. On that machine,
the standard simple plot (eg
http://matplotlib.sf.net/examples/simple_plot.py) takes about 2s to
launch. Although your machine is a bit slower and has a good bit less
memory, it's in the same ball park, and my test run is 15 times faster
than yours. I'm don't think the difference in RAM is the cause of the
difference in performance, because matplotlib doesn't use anywhere
near the amount of RAM you have on your system to make a simple plot.

Try saving`q the simple plot script linked above to your desktop and
running it by double clicking on it. Does that help? If so, you may
have an IDE conflict, as described on
http://matplotlib.sf.net/faq.html#FREEZE . Another common source of
troubles is an incompatible Numeric / numarray setting - see
http://matplotlib.sf.net/faq.html#SLOW . A third possibility is that
your system is compromised by a virus or is running so many programs
in the background (system tray) that it is out of RAM or some other
resource.

If you continue having trouble, it would help if you could post your
platform informations and other settings (see
http://matplotlib.sf.net/.matplotlibrc) to the matplotlib mailing
list.

Hope this helps,
JDH
 
H

HansWL

John Hunter said:
HansWL> I tried matplotlib 0.63 with Python 2.3.4 on an old Win98
HansWL> machine (500 MHz, 128 MB RAM) and found that I had to wait
HansWL> for at least 35 seconds before even the simplest demo plot
HansWL> appeared. Is this expected?

No it is not expected. My guess is that something may be wrong with
your configuration.

Very likely, but I do not know what.
While I don't have anything as clunky as your
machine to test on <wink>, I do have python 2.3.4 with the same
matplotlib on a 700MHz win98 box with 512 MB RAM. On that machine,
the standard simple plot (eg
http://matplotlib.sf.net/examples/simple_plot.py) takes about 2s to
launch. Although your machine is a bit slower and has a good bit less
memory, it's in the same ball park, and my test run is 15 times faster
than yours. I'm don't think the difference in RAM is the cause of the
difference in performance, because matplotlib doesn't use anywhere
near the amount of RAM you have on your system to make a simple plot.

The machine is old, but should able to deal with this. Actually,
changing the simple sine plot from 100 to 1000 points made no
difference in launch time (~ 35 s).
Try saving`q the simple plot script linked above to your desktop and
running it by double clicking on it. Does that help? If so, you may
have an IDE conflict, as described on
http://matplotlib.sf.net/faq.html#FREEZE . Another common source of
troubles is an incompatible Numeric / numarray setting - see
http://matplotlib.sf.net/faq.html#SLOW .

I was not using an IDE. Typing in commands from the DOS box gave me
the same result. I have both Numeric 23.1 and numarray 1.1 installed,
but switching between them made no difference.
A third possibility is that
your system is compromised by a virus or is running so many programs
in the background (system tray) that it is out of RAM or some other
resource.

That's not very likely. Norton Anti-virus is always on, and its virus
definition is up to date, and weekly checking is performed, no virus
was ever found. And I was not runing many programs. Actually, I
restarted Windows to run matplotlib to see if there is any difference.
None, so is getting rid of the few little programs in the system tray.
Most importantly, no other programs, including MATLAB 6.5, is behaving
this way. Of course, I am not implying that there is something wrong
with matplotlib, knowing that the Hubble people are using it to plot
large data sets. Maybe I have too much junk on my machine, and one of
them did not like matplotlib.

Maybe I should just install matplotlib on a differrent machine.

Thank you for your response.
 
J

John Hunter

HansWL> Very likely, but I do not know what.

It looks like you've tried all the obvious stuff. When you say you
switched between numarray and Numeric, I assume you mean you changed
the numerix setting in your rc file, correct?

It would be interesting to know where this performance hit is coming
from. What happens if you set backend : TkAgg and interactive : True
in your rc file, and then fire up a standard python shell

In interactive mode, all the plotting commands are acted upon when
they are issued, which should enable you to debug which of these
commands, if any, causes the long delay.

The other thing I wonder about is, is it possible that Norton is doing
some checks on python or some of the extension code that could be
causing the long startup time. Does it help to turn off the virus
software?

Cheers,
JDh
 
H

HansWL

John Hunter said:
It would be interesting to know where this performance hit is coming
from. What happens if you set backend : TkAgg and interactive : True
in your rc file, and then fire up a standard python shell


In interactive mode, all the plotting commands are acted upon when
they are issued, which should enable you to debug which of these
commands, if any, causes the long delay.

I will try this later and report back.
I did not change Numerix, but edited .matplotlibrc to switch between
Numeric and numarray. TkAgg was on by default.
The other thing I wonder about is, is it possible that Norton is doing
some checks on python or some of the extension code that could be
causing the long startup time. Does it help to turn off the virus
software?

No. I was aware of this and did disable NAV autoprotection while
trying to figure out what was wrong. No difference was observed. (NAV
does slows down the start up of IrfanView quite a bit after a virus
difination update a while back.)
 
H

HansWL

Peter Otten said:
According to

http://groups.google.com/[email protected]

Norton's "autoprotect" feature can cause a massive slow-down.

Peter

Thank you for your response.
Unfortunately, NAV is not the culprit. It does slow down some other
programs I use, though. I did try matplotlib with NAV and Norton Crash
Guard disabled, but this did not make any observable difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top