matplotlib for interactive simulation visualisation

Dear matplotlib users

On my search for a good drawing API for Python I discovered matplotlib. It has most of the features that I would like to see in a Python vector drawing API.

My problem is to visualise the process of a simulation, thus vector graphics objects controlled by a simulation program. At the moment I use a Tkinter Canvas, but it is very limiting. Look at the attached image for an example: cars driving on roads and trying to avoid crashing (Windows version). Imagine the cars driving around, of course!

What I need is something similar to the Java2D API or JGraph. I need the following features:

- interactive (by application, not user) creation and modification of graphics primitives, such as circles, text, rects, arcs, arrows, splines, etc.
- transparency (alpha blending)
- anti-aliasing
- rotation, skewing, scaling, etc.
- SVG output ?

Can matplotlib be used for visualising simulations? I do not need the axes and the various diagrams, but the rest is already there, it seems.

I have already looked at Tkinter and wxPython/OGL, but neither seems to do what I want.

Thanks for your help.
Andre

Java2D
http://java.sun.com/products/java-media/2D/index.jsp
http://java.sun.com/docs/books/tutorial/2d/display/strokeandfill.html
http://java.sun.com/j2se/1.4.2/docs/guide/2d/spec/j2d-awt.html#wp64995

JGraph
http://www.jgraph.com/showcase.html

traffic.gif

···

--
Dr. Andre P. Meyer http://home.hccnet.nl/a.meyer/
TNO FEL Command & Control and Simulation, http://www.fel.tno.nl/div2/
Delft Cooperation on Intelligent Systems, http://www.decis.nl/

--
------------------------------------------------------------------------------
The disclaimer that applies to e-mail from
TNO Physics and Electronics Laboratory
can be found on: http://www.tno.nl/disclaimer/email.html
------------------------------------------------------------------------------

AP Meyer wrote:

My problem is to visualise the process of a simulation, thus vector graphics objects controlled by a simulation program. At the moment I use a Tkinter Canvas, but it is very limiting. Look at the attached image for an example: cars driving on roads and trying to avoid crashing (Windows version). Imagine the cars driving around, of course!

Did you post a similar message to comp.lang.python? Anyway, I tried to reply to that, but maybe you didn't see it.

I would suggest my wxPython FloatCanvas package:

http://home.comcast.net/~chrishbarker/FloatCanvas/

(it's also included with recent versions of wxPython)

Sorry I don't have a really nifty page describing it, but it does come with a fairly comprehensive demo. I'd describe it's core mission as such:

* It is designed to display data, which are likely to be in arbitrary coordinates, rather than a picture, but is not a plotting tool (axes and all that)

* It is object based, and thus separates you from most of the need to understand drawing with wx (DCs and all), and lets you create and maintain objects.

* It is designed to be high performance enough for simple animation

What I need is something similar to the Java2D API or JGraph. I need

With a quick glance at the Java2D page, I can say that it has a slightly different mission, but the biggest issues are:

- No OpenGL (but I'd love to see that!)

- No printing (though I was given a patch that I have not had a chance to integrate yet. It shouldn't be too hard)

- Not as mature or Robust (maybe a half a dozen people are using it for real)

As for your requirements:

- interactive (by application, not user) creation and modification of graphics primitives, such as:

  circles - yes
text - yes
rects - yes
arcs - no, but it wouldn't be hard to add
arrows - yes, but not in the released version--hopefully I'll get anew one out soon, otherwise, I can send it to you directly.

splines, etc. -- no, but same as arcs.

- transparency (alpha blending) - No (this is NOT well supported by wx yet, :frowning: )
- anti-aliasing -- I think text is covered, but

These two could be supported by AGG, which is used by matplotlib. There was some talk a while back about creating a wxAggDC, which I could then use for FloatCanvas, but no one has stepped up to do it yet! Would you like to?

- rotation, skewing, scaling, etc. -- some,a nd it wouldn't be hard to add more.
- SVG output -- nope

wxArt2d (A C++ library for wx) has a lot of this. It would be great to see it wrapped for Python, unfortunately, not a trivial job, as I understand it.

Question: do you need it to be user-interactive, i.e. events responding to clicking on objects? FloatCanvas does have that.

I have already looked at Tkinter and wxPython/OGL, but neither seems to do what I want.

I'm afraid you're going to have to adapt anything that exists for Python, the libraries just aren't as comprehensive as to for JAVA, at least for this kind of thing. One reason is that there are quite a few GUI toolkits, so development is kind of spread thin.

If you really need the alpha blending and anti-aliasing, and matplotlib can't do what you want out of the box, I'd highly encourage you to work on a general purpose Agg module. It would be a real contribution to the community, and I'd integrate it into FloatCanvas, so you could get the rest of what you need from that. Another option would be to look at wrapping wxArt2d.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Hi Chris

Thanks for your reply. I will take a look at your FloatCanvas to see
whether it is useful for my purpose. The way you describe it might very
well.

The Agg library is awesome and making it fully available in Python would
be more than nice. The whole Python community would benefit from this.

Unfortunately, I do not have the knowledge nor the time to do the job. I
need good graphics for the simulations that I already develop on top of
the work I am paid for... The Tkinter Canvas is looking awful and
unprofessional and the API is horrible.

My feeling is that there is already a lot available*, but it needs to be
combined in the right way. Maybe it is just getting the right developers
together to give it a push. I don't know.

hope this will really move in the right direction
kind regards
Andre

* http://matplotlib.sourceforge.net/backends.html

AP Meyer wrote:
> My problem is to visualise the process of a simulation, thus vector
> graphics objects controlled by a simulation program. At the moment I use
> a Tkinter Canvas, but it is very limiting. Look at the attached image
> for an example: cars driving on roads and trying to avoid crashing
> (Windows version). Imagine the cars driving around, of course!

Did you post a similar message to comp.lang.python? Anyway, I tried to
reply to that, but maybe you didn't see it.

No.

···

On Fri, 2004-09-17 at 17:23, Chris Barker wrote:

I would suggest my wxPython FloatCanvas package:

http://home.comcast.net/~chrishbarker/FloatCanvas/

(it's also included with recent versions of wxPython)

Sorry I don't have a really nifty page describing it, but it does come
with a fairly comprehensive demo. I'd describe it's core mission as such:

* It is designed to display data, which are likely to be in arbitrary
coordinates, rather than a picture, but is not a plotting tool (axes and
all that)

* It is object based, and thus separates you from most of the need to
understand drawing with wx (DCs and all), and lets you create and
maintain objects.

* It is designed to be high performance enough for simple animation

> What I need is something similar to the Java2D API or JGraph. I need

With a quick glance at the Java2D page, I can say that it has a slightly
different mission, but the biggest issues are:

- No OpenGL (but I'd love to see that!)

- No printing (though I was given a patch that I have not had a chance
to integrate yet. It shouldn't be too hard)

- Not as mature or Robust (maybe a half a dozen people are using it for
real)

As for your requirements:

> - interactive (by application, not user) creation and modification of
> graphics primitives, such as:
  circles - yes
text - yes
rects - yes
arcs - no, but it wouldn't be hard to add
arrows - yes, but not in the released version--hopefully I'll get anew
one out soon, otherwise, I can send it to you directly.

> splines, etc. -- no, but same as arcs.

> - transparency (alpha blending) - No (this is NOT well supported by wx yet, :frowning: )
> - anti-aliasing -- I think text is covered, but

These two could be supported by AGG, which is used by matplotlib. There
was some talk a while back about creating a wxAggDC, which I could then
use for FloatCanvas, but no one has stepped up to do it yet! Would you
like to?

> - rotation, skewing, scaling, etc. -- some,a nd it wouldn't be hard to add more.
> - SVG output -- nope

wxArt2d (A C++ library for wx) has a lot of this. It would be great to
see it wrapped for Python, unfortunately, not a trivial job, as I
understand it.

Question: do you need it to be user-interactive, i.e. events responding
to clicking on objects? FloatCanvas does have that.

> I have already looked at Tkinter and wxPython/OGL, but neither seems to
> do what I want.

I'm afraid you're going to have to adapt anything that exists for
Python, the libraries just aren't as comprehensive as to for JAVA, at
least for this kind of thing. One reason is that there are quite a few
GUI toolkits, so development is kind of spread thin.

If you really need the alpha blending and anti-aliasing, and matplotlib
can't do what you want out of the box, I'd highly encourage you to work
on a general purpose Agg module. It would be a real contribution to the
community, and I'd integrate it into FloatCanvas, so you could get the
rest of what you need from that. Another option would be to look at
wrapping wxArt2d.

-Chris