Changeset 1025 for trunk/python
- Timestamp:
- 04/20/06 16:47:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asaplotbase.py
r1023 r1025 13 13 from matplotlib import rc, rcParams 14 14 from asap import rcParams as asaprcParams 15 16 15 from matplotlib.ticker import ScalarFormatter 17 16 from matplotlib.ticker import NullLocator … … 19 18 class MyFormatter(ScalarFormatter): 20 19 def __call__(self, x, pos=None): 21 last = len(self.locs)-2 22 if pos==last: 23 print "Diabling tick no " , pos, last 24 return '' # pos=-1 is the last tick 20 #last = len(self.locs)-2 21 if pos==0: 22 return '' 25 23 else: return ScalarFormatter.__call__(self, x, pos) 26 24 … … 206 204 The argument list works a bit like the matlab plot() function. 207 205 """ 208 209 206 if x is None: 210 207 if y is None: return … … 215 212 x = range(len(y)) 216 213 214 ax = self.axes 215 s = ax.title.get_size() 216 tsize = s-(self.cols+self.rows)/2 217 ax.title.set_size(tsize) 218 origx = rcParams['xtick.labelsize'] 219 origy = rcParams['ytick.labelsize'] 220 if self.cols > 1: 221 xfsize = origx-(self.cols)/2 222 #rc('xtick',labelsize=xfsize) 223 ax.xaxis.label.set_size(xfsize) 224 if self.rows > 1: 225 yfsize = origy-(self.rows)/2 226 #rc('ytick',labelsize=yfsize) 227 ax.yaxis.label.set_size(yfsize) 217 228 if mask is None: 218 229 if fmt is None: … … 238 249 239 250 line = self.axes.plot(*segments) 251 #rc('xtick',labelsize=origx) 252 #rc('ytick',labelsize=origy) 253 240 254 # Add to an existing line? 241 255 if add is None or len(self.lines) < add < 0: … … 425 439 else: 426 440 orientation = 'portrait' 427 # hack to circument ps bug in eraly versions of mpl 428 if int(mv.split(".")[1]) < 86: 429 a4w = 8.25 430 a4h = 11.25 431 ds = None 432 if orientation == 'landscape': 433 ds = min(a4h/w,a4w/h) 434 else: 435 ds = min(a4w/w,a4h/h) 436 ow = ds * w 437 oh = ds * h 438 self.figure.set_figsize_inches((ow,oh)) 439 self.canvas.print_figure(fname,orientation=orientation) 441 a4w = 8.25 442 a4h = 11.25 443 ds = None 444 if orientation == 'landscape': 445 ds = min(a4h/w,a4w/h) 446 else: 447 ds = min(a4w/w,a4h/h) 448 ow = ds * w 449 oh = ds * h 450 self.figure.set_figsize_inches((ow,oh)) 451 self.figure.savefig(fname, orientation=orientation, 452 papertype="a4") 453 # reset the figure size 454 self.figure.set_figsize_inches((w,h)) 440 455 print 'Written file %s' % (fname) 441 456 else: 442 457 if dpi is None: 443 458 dpi =150 444 self. canvas.print_figure(fname,dpi=dpi)459 self.figure.savefig(fname,dpi=dpi) 445 460 print 'Written file %s' % (fname) 446 461 except IOError, msg: … … 470 485 471 486 getattr(self.axes, "set_%s"%what)(*args, **newargs) 472 s = self.axes.title.get_size()473 tsize = s-(self.cols+self.rows)/2-1474 self.axes.title.set_size(tsize)475 if self.cols > 1:476 xfsize = self.axes.xaxis.label.get_size()-(self.cols+1)/2477 self.axes.xaxis.label.set_size(xfsize)478 if self.rows > 1:479 yfsize = self.axes.yaxis.label.get_size()-(self.rows+1)/2480 self.axes.yaxis.label.set_size(yfsize)481 487 482 488 self.show() … … 623 629 if nplots < 1 or rows*cols < nplots: 624 630 nplots = rows*cols 625 631 if ganged: 632 hsp,wsp = None,None 633 if rows > 1: hsp = 0.0001 634 if cols > 1: wsp = 0.0001 635 self.figure.subplots_adjust(wspace=wsp,hspace=hsp) 626 636 for i in range(nplots): 627 637 self.subplots.append({}) 628 629 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 638 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 630 639 cols, i+1) 631 640 self.subplots[i]['lines'] = [] 632 641 633 642 if ganged: 634 if rows > 1 or cols > 1:635 # Squeeze the plots together.636 pos = self.subplots[i]['axes'].get_position()637 if cols > 1: pos[2] *= 1.2638 if rows > 1: pos[3] *= 1.2639 self.subplots[i]['axes'].set_position(pos)640 641 643 # Suppress tick labelling for interior subplots. 642 644 if i <= (rows-1)*cols - 1: … … 651 653 tick.label1On = False 652 654 self.subplots[i]['axes'].yaxis.label.set_visible(False) 653 if (i+1)%cols: 655 # disable the first tick of [1:ncol-1] of the last row 656 if (nplots-cols) < i <= nplots-1: 654 657 self.subplots[i]['axes'].xaxis.set_major_formatter(MyFormatter()) 655 658 self.rows = rows 656 659 self.cols = cols 657 658 660 self.subplot(0) 659 661
Note:
See TracChangeset
for help on using the changeset viewer.