Welcome to SymPy (Alan Bromborsky)
[sympy.git] / examples / mplot2d.py
blobd44c3633388721dc58ed047caff1b230281ede3c
1 #!/usr/bin/env python
2 import iam_sympy_example
4 from sympy import Symbol, Basic
5 from sample import sample
7 def mplot2d(f, var, show=True):
8 """
9 Plot a 2d function using matplotlib/Tk.
10 """
12 import warnings
13 warnings.filterwarnings("ignore", "Could not match \S")
15 try:
16 import pylab as p
17 except ImportError:
18 raise ImportError("Matplotlib is required to use mplot2d.")
20 if not isinstance(f, (tuple, list)):
21 f = [f,]
23 for f_i in f:
24 x, y = sample(f_i, var)
25 p.plot(x, y)
27 p.draw()
28 if show:
29 p.show()
31 if __name__ == "__main__":
32 from sympy import sqrt, sin, log, pi
33 x = Symbol('x')
35 #mplot2d(log(x), (x, 0, 2, 100))
36 #mplot2d([sin(x), -sin(x)], (x, float(-2*pi), float(2*pi), 50))
37 mplot2d([sqrt(x), -sqrt(x), sqrt(-x), -sqrt(-x)], (x, -40.0, 40.0, 80))