TODO info improved
[sympy.git] / examples / mplot3d.py
blobb0630f1c7b970e9ceea8fbfc6175aa5882f68302
1 import sys
2 sys.path.append("..")
4 from sympy import Symbol, Basic
5 from sample import sample
7 def mplot3d(f, var1, var2, show=True):
8 """
9 Plot a 3d function using matplotlib/Tk.
10 """
12 import warnings
13 warnings.filterwarnings("ignore", "Could not match \S")
15 try:
16 import pylab as p
17 import matplotlib.axes3d as p3
18 except ImportError:
19 raise ImportError("Matplotlib is required to use mplot3d.")
21 x, y, z = sample(f, var1, var2)
23 fig = p.figure()
24 ax = p3.Axes3D(fig)
26 #ax.plot_surface(x,y,z) #seems to be a bug in matplotlib
27 ax.plot_wireframe(x,y,z)
29 ax.set_xlabel('X')
30 ax.set_ylabel('Y')
31 ax.set_zlabel('Z')
33 if show:
34 p.show()
36 if __name__ == "__main__":
37 from sympy import sin
38 x = Symbol('x')
39 y = Symbol('y')
41 mplot3d(x**2-y**2, (x, -10.0, 10.0, 20), (y, -10.0, 10.0, 20))
42 #mplot3d(x**2+y**2, (x, -10.0, 10.0, 20), (y, -10.0, 10.0, 20))
43 #mplot3d(sin(x)+sin(y), (x, -3.14, 3.14, 10), (y, -3.14, 3.14, 10))