forked from sympy/sympy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mplot3d.py
executable file
·43 lines (32 loc) · 1.05 KB
/
mplot3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import iam_sympy_example
from sympy import Symbol, Basic
from sample import sample
def mplot3d(f, var1, var2, show=True):
"""
Plot a 3d function using matplotlib/Tk.
"""
import warnings
warnings.filterwarnings("ignore", "Could not match \S")
try:
import pylab as p
import matplotlib.axes3d as p3
except ImportError:
raise ImportError("Matplotlib is required to use mplot3d.")
x, y, z = sample(f, var1, var2)
fig = p.figure()
ax = p3.Axes3D(fig)
#ax.plot_surface(x,y,z) #seems to be a bug in matplotlib
ax.plot_wireframe(x,y,z)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
if show:
p.show()
if __name__ == "__main__":
from sympy import sin
x = Symbol('x')
y = Symbol('y')
mplot3d(x**2-y**2, (x, -10.0, 10.0, 20), (y, -10.0, 10.0, 20))
#mplot3d(x**2+y**2, (x, -10.0, 10.0, 20), (y, -10.0, 10.0, 20))
#mplot3d(sin(x)+sin(y), (x, -3.14, 3.14, 10), (y, -3.14, 3.14, 10))