Last change
on this file was 13143, checked in by neise, 13 years ago |
included python -tt option. thus checking for tabs/spaces
|
File size:
1.3 KB
|
Line | |
---|
1 | #!/usr/bin/python -tt
|
---|
2 | #
|
---|
3 | # Werner Lustermann
|
---|
4 | # ETH Zurich
|
---|
5 | #
|
---|
6 | # plotter.py
|
---|
7 |
|
---|
8 | import numpy as np
|
---|
9 | import matplotlib.pyplot as plt
|
---|
10 |
|
---|
11 | class Plotter(object):
|
---|
12 | """ simple x-y plot """
|
---|
13 | def __init__(self, name, x, style = 'b', xlabel='x', ylabel='y'):
|
---|
14 | """ initialize the object """
|
---|
15 |
|
---|
16 | self.name = name
|
---|
17 | self.fig = plt.figure()
|
---|
18 | self.line, = plt.plot(x, style)
|
---|
19 |
|
---|
20 | plt.title(name)
|
---|
21 | plt.xlabel(xlabel)
|
---|
22 | plt.ylabel(ylabel)
|
---|
23 | plt.grid(True)
|
---|
24 |
|
---|
25 | def __call__(self, ydata):
|
---|
26 | """ set ydata of plot """
|
---|
27 | plt.figure(self.fig.number)
|
---|
28 | plt.ylim( np.min(ydata), np.max(ydata) )
|
---|
29 | self.line.set_ydata(ydata)
|
---|
30 | plt.draw()
|
---|
31 |
|
---|
32 | def _test():
|
---|
33 | """ test of maintaining two independant plotter instances """
|
---|
34 |
|
---|
35 | plt.ion()
|
---|
36 |
|
---|
37 | x = np.linspace(0., 10.)
|
---|
38 | plot1 = Plotter('plot1', x, 'r')
|
---|
39 | print 'plot1.fig.number: ', plot1.fig.number
|
---|
40 | plot2 = Plotter('plot2', x, 'g.')
|
---|
41 | print 'plot2.fig.number: ', plot2.fig.number
|
---|
42 |
|
---|
43 | plot1(np.sin(x) * 7.)
|
---|
44 | plot2(x*x)
|
---|
45 |
|
---|
46 | raw_input('next')
|
---|
47 |
|
---|
48 | plot1(np.cos(x) * 3.)
|
---|
49 | plot2(x)
|
---|
50 |
|
---|
51 | raw_input('next')
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | if __name__ == '__main__':
|
---|
56 | """ test the class """
|
---|
57 |
|
---|
58 | #_test_UniqueID(0)
|
---|
59 |
|
---|
60 | _test()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.