Changeset 13011 for fact/tools/pyscripts
- Timestamp:
- 03/08/12 08:30:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/plotter.py
r12992 r13011 9 9 import matplotlib.pyplot as plt 10 10 11 class UniqueID(object):12 """ provide a unique identifier accross objects """13 14 def __init__(self, start_value=1):15 """ initialize the object """16 17 self.value = start_value18 19 def __call__(self):20 """ return the present id and compute the next one """21 22 value = self.value23 self.value += 124 25 return(value)26 27 def _test_UniqueID(start_value=1):28 29 fig_id = UniqueID(start_value)30 31 for i in range(10):32 print 'fig_id: ', fig_id()33 34 35 11 class Plotter(object): 36 12 """ simple x-y plot """ 37 def __init__(self, name, x, my_id,style = 'b', xlabel='x', ylabel='y'):13 def __init__(self, name, x, style = 'b', xlabel='x', ylabel='y'): 38 14 """ initialize the object """ 39 15 40 16 self.name = name 41 self.fig_id = my_id() 42 plt.figure(self.fig_id) 17 self.fig = plt.figure() 43 18 self.line, = plt.plot(x, style) 44 19 … … 50 25 def __call__(self, ydata): 51 26 """ set ydata of plot """ 52 plt.figure(self.fig _id)27 plt.figure(self.fig.number) 53 28 plt.ylim( np.min(ydata), np.max(ydata) ) 54 29 self.line.set_ydata(ydata) … … 58 33 """ test of maintaining two independant plotter instances """ 59 34 60 plotter_id = UniqueID(1)61 35 plt.ion() 62 36 63 37 x = np.linspace(0., 10.) 64 plot1 = Plotter('plot1', x, plotter_id,'r')65 print 'plot1.fig _id: ', plot1.fig_id66 plot2 = Plotter('plot2', x, plotter_id,'g.')67 #print 'plot2.fig_id: ', plot2.fig_id38 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 68 42 69 43 plot1(np.sin(x) * 7.)
Note:
See TracChangeset
for help on using the changeset viewer.