Changeset 710 for trunk/python/asapplotter.py
- Timestamp:
- 11/11/05 10:01:49 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r709 r710 12 12 """ 13 13 def __init__(self, visible=True): 14 15 if visible: 16 from asap.asaplotgui import asaplotgui as asaplot 17 else: 18 from asap.asaplot import asaplot 19 self._plotter = asaplot() 20 14 15 self._visible = visible 16 self._plotter = self._newplotter() 17 21 18 self._tdict = {'Time':'t','time':'t','t':'t','T':'t'} 22 19 self._bdict = {'Beam':'b','beam':'b','b':'b','B':'b'} … … 45 42 self._minmaxx = None 46 43 self._minmaxy = None 47 44 self._datamask = None 48 45 self._data = None 49 46 self._lmap = None … … 55 52 'i':None, 'p':None 56 53 } 54 self._usermask = None 55 self._usermaskspectra = None 56 57 def _newplotter(self): 58 if self._visible: 59 from asap.asaplotgui import asaplotgui as asaplot 60 else: 61 from asap.asaplot import asaplot 62 return asaplot() 63 57 64 58 65 def _translate(self, name): … … 73 80 are consistent e.g. all 'channel' or all 'velocity' etc. 74 81 """ 75 76 self._plotter = ASAPlot()82 if self._plotter.is_dead: 83 self._plotter = self._newplotter() 77 84 self._plotter.hold() 78 85 self._plotter.clear() … … 81 88 if list(args) != self._data: 82 89 self._data = list(args) 83 # reset cursor84 self. set_cursor(refresh=False)90 # reset 91 self._reset() 85 92 else: 86 self._data = list(args) 87 self.set_cursor(refresh=False) 93 if isinstance(args[0], list): 94 self._data = args[0] 95 else: 96 self._data = list(args) 97 self._reset() 88 98 # ranges become invalid when unit changes 89 99 if self._abcunit != self._data[0].get_unit(): … … 91 101 self._minmaxy = None 92 102 self._abcunit = self._data[0].get_unit() 93 103 self._datamask = None 94 104 if self._panelling == 't': 95 105 maxrows = 25 … … 125 135 ncol = eval(self._cdict.get(colmode)) 126 136 if n > 1: 137 ganged = rcParams['plotter.ganged'] 127 138 if self._rows and self._cols: 128 139 n = min(n,self._rows*self._cols) 129 140 self._plotter.set_panels(rows=self._rows,cols=self._cols, 130 nplots=n )141 nplots=n,ganged=ganged) 131 142 else: 132 self._plotter.set_panels(rows=n,cols=0,nplots=n )143 self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 133 144 else: 134 145 self._plotter.set_panels() … … 171 182 if self._abcissa: xlab = self._abcissa 172 183 y = None 184 m = scan._getmask(rowsel) 185 if self._usermask and self._usermask.count(j): 186 m = logical_and(self._usermask, m) 173 187 if polmode == "stokes": 174 188 y = scan._getstokesspectrum(rowsel) … … 184 198 ylab = scan._get_ordinate_label() 185 199 m = scan._getmask(rowsel) 186 187 188 200 if self._datamask is not None: 201 if len(m) == len(self._datamask): 202 m = logical_and(m,self._datamask) 189 203 if self._lmap and len(self._lmap) > 0: 190 204 llab = self._lmap[jj] … … 200 214 y = y[s:e] 201 215 m = m[s:e] 216 if len(x) > 1024 and rcParams['plotter.decimate']: 217 fac = len(x)/1024 218 x = x[::fac] 219 m = m[::fac] 220 y = y[::fac] 202 221 self._plotter.plot(x,y,m) 203 222 xlim=[min(x),max(x)] 204 223 if self._minmaxx is not None: 205 206 224 xlim = self._minmaxx 225 self._plotter.axes.set_xlim(xlim) 207 226 self._plotter.set_axes('xlabel',xlab) 208 227 self._plotter.set_axes('ylabel',ylab) … … 211 230 212 231 def _plot_scans(self, scans, colmode): 213 print " Can only plot one row per scan."232 print "Plotting mode is scans across panels. Can only plot one row per scan." 214 233 if colmode == 's': 215 234 return … … 227 246 ncol = eval(self._cdict.get(colmode)) 228 247 if n > 1: 248 ganged = rcParams['plotter.ganged'] 229 249 if self._rows and self._cols: 230 250 n = min(n,self._rows*self._cols) 231 251 self._plotter.set_panels(rows=self._rows,cols=self._cols, 232 nplots=n )252 nplots=n,ganged=ganged) 233 253 else: 234 self._plotter.set_panels(rows=n,cols=0,nplots=n )254 self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 235 255 else: 236 256 self._plotter.set_panels() … … 280 300 ylab = scan._get_ordinate_label() 281 301 m = scan._getmask(rowsel) 282 if self._datamask is not None: 283 if len(m) == len(self._datamask): 284 m = logical_and(m,self._datamask) 302 if self._usermask and self._usermask.count(j): 303 m = logical_and(self._usermask, m) 285 304 if self._lmap and len(self._lmap) > 0: 286 305 llab = self._lmap[jj] … … 296 315 y = y[s:e] 297 316 m = m[s:e] 298 317 if len(x) > 1024 and rcParams['plotter.decimate']: 318 fac = len(x)/1024 319 x = x[::fac] 320 m = m[::fac] 321 y = y[::fac] 299 322 self._plotter.plot(x,y,m) 300 323 xlim=[min(x),max(x)] 301 324 if self._minmaxx is not None: 302 325 xlim = self._minmaxx 303 326 self._plotter.axes.set_xlim(xlim) 304 327 … … 325 348 ncol = eval(self._cdict.get(colmode)) 326 349 if n > 1: 350 ganged = rcParams['plotter.ganged'] 327 351 if self._rows and self._cols: 328 352 n = min(n,self._rows*self._cols) 329 353 self._plotter.set_panels(rows=self._rows,cols=self._cols, 330 nplots=n )354 nplots=n,ganged=ganged) 331 355 else: 332 self._plotter.set_panels(rows=n,cols=0,nplots=n )356 self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 333 357 else: 334 358 self._plotter.set_panels() … … 390 414 ylab = scan._get_ordinate_label() 391 415 m = scan._getmask(rowsel) 392 if self._datamask is not None:393 if len(m) == len(self._datamask): 394 m = logical_and(m,self._datamask) 416 if self._usermask and self._usermask.count(j): 417 m = logical_and(self._usermask, m) 418 395 419 if colmode == 's' or colmode == 't': 396 420 if self._title and len(self._title) > 0: … … 426 450 y = y[s:e] 427 451 m = m[s:e] 428 452 if len(x) > 1024 and rcParams['plotter.decimate']: 453 fac = len(x)/1024 454 x = x[::fac] 455 m = m[::fac] 456 y = y[::fac] 429 457 self._plotter.plot(x,y,m) 430 458 xlim=[min(x),max(x)] 431 459 if self._minmaxx is not None: 432 460 xlim = self._minmaxx 433 461 self._plotter.axes.set_xlim(xlim) 434 462 … … 445 473 Parameters: 446 474 stacking: tell the plotter which variable to plot 447 as line colo ur overlays (default 'pol')475 as line color overlays (default 'pol') 448 476 panelling: tell the plotter which variable to plot 449 477 across multiple panels (default 'scan' … … 531 559 mp: a list of 'strings'. This should have the same length 532 560 as the number of elements on the legend and then maps 533 to the indeces in order 561 to the indeces in order. It is possible to uses latex 562 math expression. These have to be enclosed in r'', e.g. r'$x^{2}$' 534 563 535 564 Example: … … 537 566 for CO and SiO: 538 567 plotter.set_stacking('i') 539 plotter.set_legend _map(['CO','SiO'])568 plotter.set_legend(['CO','SiO']) 540 569 plotter.plot() 570 plotter.set_legend([r'$^{12}CO$', r'SiO']) 541 571 """ 542 572 self._lmap = mp … … 545 575 546 576 def set_title(self, title=None): 577 """ 578 Set the title of the plot. If multiple panels are plotted, 579 multiple titles have to be specified. 580 Example: 581 # two panels are visible on the plotter 582 plotter.set_title(["First Panel","Second Panel"]) 583 """ 547 584 self._title = title 548 585 if self._data: self.plot() … … 550 587 551 588 def set_ordinate(self, ordinate=None): 589 """ 590 Set the y-axis label of the plot. If multiple panels are plotted, 591 multiple labels have to be specified. 592 Example: 593 # two panels are visible on the plotter 594 plotter.set_ordinate(["First Y-Axis","Second Y-Axis"]) 595 """ 552 596 self._ordinate = ordinate 553 597 if self._data: self.plot() … … 555 599 556 600 def set_abcissa(self, abcissa=None): 601 """ 602 Set the x-axis label of the plot. If multiple panels are plotted, 603 multiple labels have to be specified. 604 Example: 605 # two panels are visible on the plotter 606 plotter.set_ordinate(["First X-Axis","Second X-Axis"]) 607 """ 557 608 self._abcissa = abcissa 558 609 if self._data: self.plot() 559 610 return 560 611 561 def save(self, filename=None, orientation=None,dpi=None): 612 def set_colors(self, colormap): 613 """ 614 Set the colors to be used. The plotter will cycle through 615 these colors when lines are overlaid (stacking mode). 616 Example: 617 plotter.set_colors("red green blue") 618 # If for example four lines are overlaid e.g I Q U V 619 # 'I' will be 'red', 'Q' will be 'green', U will be 'blue' 620 # and 'V' will be 'red' again. 621 """ 622 if isinstance(colormap,str): 623 colormap = colormap.split() 624 self._plotter.palette(0,colormap=colormap) 625 if self._data: self.plot() 626 627 def set_linestyles(self, linestyles): 628 """ 629 Parameters: 630 linestyles: a list of linestyles to use. 631 'line', 'dashed', 'dotted', 'dashdot', 632 'dashdotdot' and 'dashdashdot' are 633 possible 634 635 Set the linestyles to be used. The plotter will cycle through 636 these linestyles when lines are overlaid (stacking mode) AND 637 only one color has been set. 638 Example: 639 plotter.set_colors("black") 640 plotter.set_linestyles("line dashed dotted dashdot") 641 # If for example four lines are overlaid e.g I Q U V 642 # 'I' will be 'solid', 'Q' will be 'dashed', 643 # U will be 'dotted' and 'V' will be 'dashdot'. 644 """ 645 if isinstance(linestyles,str): 646 linestyles = linestyles.split() 647 self._plotter.palette(color=0,linestyle=0,linestyles=linestyles) 648 if self._data: self.plot() 649 650 def save(self, filename=None, orientation=None, dpi=None): 562 651 """ 563 652 Save the plot to a file. The know formats are 'png', 'ps', 'eps'. … … 572 661 If None is choosen for 'ps' output, the plot is 573 662 automatically oriented to fill the page. 663 dpi: The dpi of the output non-ps plot 574 664 """ 575 665 self._plotter.save(filename,orientation,dpi) … … 640 730 dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3} 641 731 draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3} 642 dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag e(RL)":3}732 dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3} 643 733 644 734 if pol is None: … … 677 767 if self._data and refresh: self.plot() 678 768 769 def set_mask(self, mask=None, pol=None): 770 if not self._data: 771 print "Can only set cursor after a first call to plot()" 772 return 773 if isinstance(mask, array): 774 self._usermask = mask 775 if isinstance(mask, list): 776 self._usermask = array(mask) 777 if mask is None and pol is None: 778 self._usermask = None 779 self._usermaskspectra = None 780 781 dstokes = {"I":0,"Q":1,"U":2,"V":3} 782 dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3} 783 draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3} 784 dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3} 785 if isinstance(pol, str): 786 pol = pol.split() 787 if isinstance(pol, list): 788 if isinstance(pol[0], str): 789 pass 790 else: 791 cpos = self._cursor[self._stacking] 792 self._usermaskspectra =filter(lambda i: filter(lambda j: j==i ,cpos),pol) 793 else: 794 return 795 self.plot() 796 679 797 def _get_pollabel(self, scan, polmode): 680 798 tlab = "" … … 711 829 return start,end 712 830 713 #if __name__ == '__main__': 714 # plotter = asapplotter() 831 def _reset(self): 832 self._usermask = None 833 self._usermaskspectra = None 834 self.set_cursor(refresh=False)
Note: See TracChangeset
for help on using the changeset viewer.