- Timestamp:
- 01/18/05 17:15:27 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asaplot.py
r187 r202 28 28 """ 29 29 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): 31 31 """ 32 32 Create a new instance of the ASAPlot plotting class. … … 42 42 43 43 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, 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) 49 49 self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) 50 50 … … 64 64 65 65 # 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'] 67 67 self.attributes = {} 68 68 self.loc = 1 … … 490 490 if rows < 1: 491 491 rows = 1 492 492 nel = 1 493 493 if cols == 0: 494 nel = rows 494 495 i = int(sqrt(rows)) 495 496 if i*i < rows: i += 1 … … 498 499 if i*(i-1) >= rows: i -= 1 499 500 rows = i 500 501 501 502 if 0 <= n < rows*cols: 502 503 i = len(self.subplots) … … 510 511 else: 511 512 self.subplots = [] 512 for i in range(0, rows*cols):513 for i in range(0,nel): 513 514 self.subplots.append({}) 514 515 self.subplots[i]['axes'] = self.figure.add_subplot(rows, … … 536 537 if not self.buffering: 537 538 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((' ')) 554 556 555 557 self.window.wm_deiconify() … … 595 597 """ 596 598 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 597 626 598 627
Note:
See TracChangeset
for help on using the changeset viewer.