Tuesday, July 17, 2007

SymPy Plotting: Improved Usability with Pyglet

One of my personal goals for the SymPy plotting module is to introduce non-programmers to Python. This means it needs to have a familiar interface, and that it should "just work" straight out-of-the-box. With the latest code in SVN, you can now use Plot in Python 2.5 without installing any additional dependencies. In Python 2.4 and 2.3, the only external dependency is ctypes.

PyOpenGL is no longer used at all (no offense to Mike Fletcher and his loyal followers). After it was suggested last week, I'm now including a (stripped-down) version of Pyglet, which provides a ctypes-only OpenGL wrapper, in addition to excellent windowing, keyboard, and mouse support. Pyglet's event model is also compatible with the multi-threaded interface I described last week. That means you can now do this:
>>> from sympy import Symbol
>>> from sympy.modules.plotting import Plot
>>> x,y = Symbol('x'),Symbol('y')
>>> p = Plot(width=300, height=250, bbox=True)

>>> p[1] = x**2-y**2, [x,-1,1], [y,-1,1]

>>> p[1] =  x**2+y**2, [x,-1.0,1.0], [y,-1.0,1.0]
>>> p[2] = -x**2-y**2, [x,-1.0,1.0], [y,-1.0,1.0]
>>> print p
[1]: x**2+y**2, [x,-1.0,1.0], [y,-1.0,1.0]
[2]: -x**2-y**2, [x,-1.0,1.0], [y,-1.0,1.0]
Also new:
  • Rotation mechanism based on a virtual trackball.
  • Scroll-wheel zoom.
  • Holding the shift key allows more precise movement.
  • Smooth time-based keyboard movement.
  • Added arrow and page up/down key control (ASDWRF is still there).
  • X,Y, and Z-blended coloring scheme.
In progress:
  • Configurable coloring.
  • Labeled coordinate axes.
  • Translation in the plane of the screen.
  • Automatic intervals.
  • Intuitive 2d support, including dynamic intervals.
  • Display lists (maybe faster for higher-resolution rendering, we'll see).
  • Anti-aliasing.
Let me know when you get a chance to try it out!


Brian Jorgensen said...

I have no imagination for functions to test and/or demo, as you can see from my repeated use of ellipsoids, saddles, and trig functions. Any suggestions, and in particular real-world examples, would be appreciated! ;-)

Alex said...



Jason G said...

I was saddened to find that it no longer works in my virtual machine. I always get "ContextException: No conforming visual exists" :(