Changeset 202


Ignore:
Timestamp:
01/18/05 17:15:27 (19 years ago)
Author:
mar637
Message:
  • removed internal self.frame1 to fix resizing bug.
  • removed 'white' from default colors.
  • added set_limits to set a "zoom" window
  • added save function to save plotter from the command line
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asaplot.py

    r187 r202  
    2828    """
    2929
    30     def __init__(self, rows=1, cols=0, title='', size=(8,6), buffering=False):
     30    def __init__(self, rows=1, cols=0, title='', size=(7,5), buffering=False):
    3131        """
    3232        Create a new instance of the ASAPlot plotting class.
     
    4242       
    4343        self.window.protocol("WM_DELETE_WINDOW", dest_callback)
    44         self.frame1 = Tk.Frame(self.window, relief=Tk.RIDGE, borderwidth=4)
    45         self.frame1.pack(fill=Tk.BOTH)
    46 
    47         self.figure = Figure(figsize=size, facecolor='#ddddee')
    48         self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame1)
     44        #self.frame1 = Tk.Frame(self.window, relief=Tk.RIDGE, borderwidth=4)
     45        #self.frame1.pack(fill=Tk.BOTH)
     46
     47        self.figure = Figure(figsize=size,facecolor='#ddddee')
     48        self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
    4949        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    5050
     
    6464
    6565        # Set matplotlib default colour sequence.
    66         self.colours = [1, 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']
     66        self.colours = [1, 'b', 'g', 'r', 'c', 'm', 'y', 'k']
    6767        self.attributes = {}
    6868        self.loc = 1
     
    490490        if rows < 1:
    491491            rows = 1
    492 
     492        nel = 1
    493493        if cols == 0:
     494            nel = rows
    494495            i = int(sqrt(rows))
    495496            if i*i < rows: i += 1
     
    498499            if i*(i-1) >= rows: i -= 1
    499500            rows = i
    500 
     501           
    501502        if 0 <= n < rows*cols:
    502503            i = len(self.subplots)
     
    510511        else:
    511512            self.subplots = []
    512             for i in range(0,rows*cols):
     513            for i in range(0,nel):
    513514                self.subplots.append({})
    514515                self.subplots[i]['axes']  = self.figure.add_subplot(rows,
     
    536537        if not self.buffering:
    537538            if self.loc:
    538                 lines  = []
    539                 labels = []
    540                 i = 0
    541                 for line in self.lines:
    542                     i += 1
    543                     if line is not None:
    544                         lines.append(line[0])
    545                         lbl = line[0].get_label()
    546                         if lbl == '':
    547                             lbl = str(i)
    548                         labels.append(lbl)
    549 
    550                 if len(lines):
    551                     self.axes.legend(tuple(lines), tuple(labels), self.loc)
    552                 else:
    553                     self.axes.legend((' '))
     539                for j in range(len(self.subplots)):
     540                    lines  = []
     541                    labels = []
     542                    i = 0
     543                    for line in self.subplots[j]['lines']:
     544                        i += 1
     545                        if line is not None:
     546                            lines.append(line[0])
     547                            lbl = line[0].get_label()
     548                            if lbl == '':
     549                                lbl = str(i)
     550                            labels.append(lbl)
     551
     552                    if len(lines):
     553                        self.subplots[j]['axes'].legend(tuple(lines), tuple(labels), self.loc)
     554                    else:
     555                        self.subplots[j]['axes'].legend((' '))
    554556
    555557            self.window.wm_deiconify()
     
    595597        """
    596598        self.window.wm_withdraw()
     599
     600    def set_limits(self,xlim=None,ylim=None):
     601        for s in self.subplots:
     602            self.axes  = s['axes']
     603            self.lines = s['lines']
     604            if xlim is not None:
     605                self.axes.set_xlim(xlim)
     606            if ylim is not None:
     607                self.axes.set_ylim(ylim)
     608        return
     609
     610    def save(self, fname=None):
     611        if fname is None:
     612            from datetime import datetime
     613            dstr = datetime.now().strftime('%Y%m%d_%H%M%S')
     614            fname = 'asap'+dstr+'.png'
     615           
     616        d = ['png','.ps','eps']
     617        if fname[-3:].lower() in d:
     618            try:
     619                self.canvas.print_figure(fname)
     620            except IOError, msg:
     621                print 'Failed to save %s: Error msg was\n\n%s' % (fname, err)
     622                return
     623        else:
     624            print "Invalid image type. Valid types are:"
     625            print d
    597626
    598627
Note: See TracChangeset for help on using the changeset viewer.