4

I am looking for a Python package that will allow me to plot something similar to the Java applet seen below:

http://math.mit.edu/mathlets/mathlets/isoclines/

Does anyone know any ODE plotting packages for this? I can code something from scratch using Numpy, Matplotlib, but I wanted to ask around first.

Thanks,

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
BBSysDyn
  • 4,389
  • 8
  • 48
  • 63
  • 1
    Will matplotlib's quiver do something like this? http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.quiver and http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html – Thomas K Jun 16 '11 at 11:55
  • yes quiver apparently can help here, i saw some examples for it too. – BBSysDyn Jun 16 '11 at 12:35

2 Answers2

3

I wrote something like this, it seems to work for y'=y^2-x

from pylab import *
xmax = 4.0
xmin = -xmax
D = 20
ymax = 4.0
ymin = -ymax
x = linspace(xmin, xmax, D)
y = linspace(ymin, ymax, D)
X, Y = meshgrid(x, y)
deg = arctan(Y**2 - X)
QP = quiver(X,Y,cos(deg),sin(deg))
show()

enter image description here

BBSysDyn
  • 4,389
  • 8
  • 48
  • 63
1

Sage will do this:

x,y = var("x y")
eq = y^3-3*y-x
p = implicit_plot(eq==0,(x,-4,4),(y,-4,4))
p += plot_slope_field(eq, (x,-4,4),(y,-4,4), headlength=1e-8)
p.show(aspect_ratio=1)

although it's simply wrapping matplotlib functionality for the graphics. (To be perfectly honest, the matplotlib wrapping isn't as good as it could be yet, which often causes me headaches.)

example

DSM
  • 342,061
  • 65
  • 592
  • 494
  • i looked at sage, the source code is huge, does it support python out of the box? is the code above python code? – BBSysDyn Jun 16 '11 at 12:38
  • Yeah, it's pretty big: it's a collection of math tools and libraries wrapped in Python. But if everything you're doing is numerical, and you don't need symbolics, then it's probably easiest just to use matplotlib directly (as, after all, that's what Sage is doing behind the scenes.) – DSM Jun 16 '11 at 13:57
  • 1
    You can use sage on the web, without installing it, if you prefer: http://www.sagenb.org/ – Thomas K Jun 16 '11 at 16:53
  • thx for the info, but I got into this so I would have local code instead of "mathlets" that are applets. – BBSysDyn Jun 16 '11 at 17:08