Changeset 13011 for fact


Ignore:
Timestamp:
03/08/12 08:30:46 (13 years ago)
Author:
lusterma
Message:
use plt.figure.number instead of UniqueID, class UniqueID removed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/pyfact/plotter.py

    r12992 r13011  
    99import matplotlib.pyplot as plt
    1010
    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_value
    18        
    19     def __call__(self):
    20         """ return the present id and compute the next one """
    21        
    22         value = self.value
    23         self.value += 1
    24        
    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 
    3511class Plotter(object):
    3612    """ 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'):
    3814        """ initialize the object """
    3915       
    4016        self.name  = name
    41         self.fig_id = my_id()
    42         plt.figure(self.fig_id)
     17        self.fig   = plt.figure()
    4318        self.line, = plt.plot(x, style)
    4419       
     
    5025    def __call__(self, ydata):
    5126        """ set ydata of plot """
    52         plt.figure(self.fig_id)
     27        plt.figure(self.fig.number)
    5328        plt.ylim( np.min(ydata), np.max(ydata) )
    5429        self.line.set_ydata(ydata)
     
    5833    """ test of maintaining two independant plotter instances """
    5934   
    60     plotter_id = UniqueID(1)
    6135    plt.ion()
    6236   
    6337    x = np.linspace(0., 10.)
    64     plot1 = Plotter('plot1', x, plotter_id, 'r')
    65     print 'plot1.fig_id: ', plot1.fig_id
    66     plot2 = Plotter('plot2', x, plotter_id, 'g.')
    67     #print 'plot2.fig_id: ', plot2.fig_id
     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
    6842   
    6943    plot1(np.sin(x) * 7.)
Note: See TracChangeset for help on using the changeset viewer.