Sunday, May 13, 2007

New direction for SymPy Graphing

In addition to gaining some new perspective on my project this weekend, I've gotten a lot done.



On Friday, I said I wanted to stop supporting matplotlib and to begin focusing on a fresh OpenGL plotting solution. It turns out that matplotlib has better 3d support than I suggested, though it is buggy and still doesn't have everything I need. Fortunately, it turns out we can have it both ways.

I've moved matplotlib 2d plotting support out of modules/graphing.py and into examples/mplot2d.py. I've also added 3d plotting support in examples/mplot3d.py. In accomplishing this, I created a generic sampling function in modules/graphing.py which generates plotting data from a 2d or 3d function over an interval or rectangle:


>>> from sympy.modules.graphing import sample
>>> from sympy import Symbol
>>> x = Symbol('x')
>>> sample(x, (x, 0, 2, 2))
[[0,1,2],[0,1,2]]
>>> sample(x**2, (x, 1, 3, 2))
[[1,2,3], [1,4,9]]


This approach will allow me to support multiple plotting solutions. You should now be able to graph many varieties of functions using matplotlib with the implementations in examples/mplot2d.py and examples/mplot3d.py.


>>> mplot3d(x**2-y**2, (x, -10.0, 10.0, 20), (y, -10.0, 10.0, 20))


1 comment:

Ondrej Certik said...

I checked your code and it looks good, it's nicely written and well documented and it works. :)

It's a nice idea to put it into examples. This way we can easily use matplotlib and your new graphing code.

So I guess now you can try to write your pyopengl code.