Changeset 652
- Timestamp:
- 06/22/05 15:54:38 (19 years ago)
- Location:
- trunk/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapfitter.py
r626 r652 331 331 self._p.clear() 332 332 self._p.set_panels() 333 self._p.palette( 1)333 self._p.palette(0) 334 334 tlab = 'Spectrum' 335 335 xlab = 'Abcissa' … … 342 342 343 343 colours = ["grey60","grey80","red","orange","purple","green","magenta", "cyan"] 344 self._p.palette( 1,colours)344 self._p.palette(0,colours) 345 345 self._p.set_line(label='Spectrum') 346 346 self._p.plot(self.x, self.y, m) 347 347 if residual: 348 self._p.palette( 2)348 self._p.palette(1) 349 349 self._p.set_line(label='Residual') 350 350 self._p.plot(self.x, self.get_residual(), m) 351 self._p.palette( 3)351 self._p.palette(2) 352 352 if components is not None: 353 353 cs = components … … 356 356 self._p.text(0.15,0.15,str(self.get_parameters()[2]),size=8) 357 357 n = len(self.components) 358 self._p.palette( 4)358 self._p.palette(3) 359 359 for c in cs: 360 360 if 0 <= c < n: … … 363 363 self._p.plot(self.x, self.fitter.evaluate(c), m) 364 364 elif c == -1: 365 self._p.palette( 3)365 self._p.palette(2) 366 366 self._p.set_line(label="Total Fit") 367 367 self._p.plot(self.x, self.get_fit(), m) 368 368 else: 369 self._p.palette( 3)369 self._p.palette(2) 370 370 self._p.set_line(label='Fit') 371 371 self._p.plot(self.x, self.get_fit(), m) -
trunk/python/asaplot.py
r620 r652 21 21 matplotlib.rcParams['toolbar'] = 'toolbar2' 22 22 23 # Colour dictionary.24 colours = {}25 26 23 class ASAPlot: 27 24 """ … … 63 60 64 61 # Set matplotlib default colour sequence. 65 self.colours = [1, 'b', 'g', 'r', 'c', 'm', 'y', 'k'] 62 self.colormap = ['blue', 'green', 'red', 'cyan', 'magenta', 'yellow', 'black', 'purple', 'orange', 'pink'] 63 self.color = 0; 66 64 self.attributes = {} 67 65 self.loc = 0 … … 78 76 """ 79 77 80 for i in range( 1,len(self.lines)+1):78 for i in range(len(self.lines)): 81 79 self.delete(i) 82 80 self.axes.clear() 83 self.colo urs[0] = 181 self.color = 0 84 82 self.lines = [] 85 83 84 85 def palette(self, color, colormap=None): 86 if colormap: 87 self.colormap = colormap 88 if 0 <= color < len(self.colormap): 89 self.color = color 86 90 87 91 def delete(self, numbers=None): … … 179 183 180 184 181 def palette(self, pen=None, colours=None):182 """183 Redefine the colour sequence.184 185 pen is the pen number to use for the next plot; this will be auto-186 incremented.187 188 colours is the list of pen colours. Colour may be specified via189 the single letter values understood by matplotlib:190 191 b: blue192 g: green193 r: red194 c: cyan195 m: magenta196 y: yellow197 k: black198 w: white199 200 or via the full name as listed in the colour dictionary which is201 loaded by default by load_colours() from rgb.txt and listed by202 list_colours().203 """204 205 if pen is None and colours is None:206 self.colours = []207 return208 209 if pen is None:210 if not len(self.colours):211 self.colours = [1]212 else:213 self.colours[0] = pen214 215 if colours is None:216 return217 218 cols = []219 for col in colours:220 cols.append(get_colour(col))221 222 self.colours[1:] = cols223 224 if 0 > self.colours[0] > len(self.colours):225 self.colours[0] = 1226 227 185 228 186 def plot(self, x=None, y=None, mask=None, fmt=None, add=None): … … 283 241 getattr(segment, "set_%s"%k)(v) 284 242 285 if not gotcolour and len(self.colo urs):243 if not gotcolour and len(self.colormap): 286 244 for segment in self.lines[i]: 287 getattr(segment, "set_color")(self.colo urs[self.colours[0]])288 289 self.colo urs[0]+= 1290 if self.colo urs[0] >= len(self.colours):291 self.colo urs[0] = 1245 getattr(segment, "set_color")(self.colormap[self.color]) 246 247 self.color += 1 248 if self.color >= len(self.colormap): 249 self.color = 0 292 250 293 251 self.show() … … 464 422 465 423 newargs = {} 424 466 425 for k, v in kwargs.iteritems(): 467 426 k = k.lower() 468 427 if k == 'colour': k = 'color' 469 470 if k == 'color':471 v = get_colour(v)472 473 428 newargs[k] = v 474 429 … … 486 441 if what is None: return 487 442 if what[-6:] == 'colour': what = what[:-6] + 'color' 488 if what[-5:] == 'color' and len(args):489 args = (get_colour(args[0]),)443 #if what[-5:] == 'color' and len(args): 444 # args = (get_colour(args[0]),) 490 445 491 446 newargs = {} … … 493 448 k = k.lower() 494 449 if k == 'colour': k = 'color' 495 496 if k == 'color':497 v = get_colour(v)498 499 450 newargs[k] = v 500 451 … … 556 507 if k == 'colour': k = 'color' 557 508 558 if k == 'color':559 v = get_colour(v)560 561 509 if 0 <= number < len(self.lines): 562 510 if self.lines[number] is not None: … … 743 691 """ 744 692 self.window.wm_withdraw() 745 746 747 def get_colour(colour='black'):748 """749 Look up a colour by name in the colour dictionary. Matches are750 case-insensitive, insensitive to blanks, and 'gray' matches 'grey'.751 """752 753 if colour is None: return None754 755 if match('[rgbcmykw]$', colour): return colour756 if match('#[\da-fA-F]{6}$', colour): return colour757 758 if len(colours) == 0: load_colours()759 760 # Try a quick match.761 if colours.has_key(colour): return colours[colour]762 763 colour = colour.replace(' ','').lower()764 colour = colour.replace('gray','grey')765 for name in colours.keys():766 if name.lower() == colour:767 return colours[name]768 769 return '#000000'770 771 772 def list_colours():773 """774 List the contents of the colour dictionary sorted by name.775 """776 777 if len(colours) == 0: load_colours()778 779 names = colours.keys()780 names.sort()781 for name in names:782 print colours[name], name783 784 785 def load_colours(filename='/usr/local/lib/rgb.txt'):786 """787 Load the colour dictionary from the specified file.788 """789 print 'Loading colour dictionary from', filename790 from os.path import expandvars791 filename = expandvars(filename)792 rgb = open(filename, 'r')793 794 while True:795 line = rgb.readline()796 if line == '': break797 tmp = line.split()798 799 if len(tmp) == 4:800 if tmp[3][:4] == 'gray': continue801 if tmp[3].lower().find('gray') != -1: continue802 803 name = tmp[3][0].upper() + tmp[3][1:]804 r, g, b = int(tmp[0]), int(tmp[1]), int(tmp[2])805 colours[name] = '#%2.2x%2.2x%2.2x' % (r, g, b) -
trunk/python/asapplotter.py
r626 r652 121 121 self._plotter.set_panels() 122 122 rows = self._cursor["t"] 123 self._plotter.palette( 1)123 self._plotter.palette(0) 124 124 for rowsel in rows: 125 125 i = self._cursor["t"].index(rowsel) 126 126 if n > 1: 127 self._plotter.palette( 1)127 self._plotter.palette(0) 128 128 self._plotter.subplot(i) 129 129 colvals = eval(cdict2.get(colmode)) … … 214 214 215 215 for scan in scans: 216 self._plotter.palette( 1)216 self._plotter.palette(0) 217 217 if n > 1: 218 218 self._plotter.subplot(scans.index(scan)) 219 self._plotter.palette(1)220 219 colvals = eval(cdict2.get(colmode)) 221 220 rowsel = self._cursor["t"][0] … … 302 301 panels = self._cursor[self._panelling] 303 302 for i in panels: 304 self._plotter.palette( 1)303 self._plotter.palette(0) 305 304 polmode = "raw" 306 305 ii = self._cursor[self._panelling].index(i) … … 360 359 if self._title and len(self._title) > 0: 361 360 tlab = self._title[ii] 362 else: 363 tlab = self._ldict.get(self._panelling)+' '+str(i) 361 else: 362 if self._panelling == 'p': 363 tlab = self._get_pollabel(scan, polmode) 364 else: 365 tlab = self._ldict.get(self._panelling)+' '+str(i) 364 366 if self._lmap and len(self._lmap) > 0: 365 367 llab = self._lmap[jj] … … 512 514 return 513 515 514 def save(self, filename=None ):516 def save(self, filename=None, orientation='landscape'): 515 517 """ 516 518 Save the plot to a file. The know formats are 'png', 'ps', 'eps'. … … 521 523 called 'yyyymmdd_hhmmss.png' is created in the 522 524 current directory. 523 """ 524 self._plotter.save(filename) 525 orientation: optional parameter for postscript. 'landscape' 526 (default) and 'portrait' are valid. 527 """ 528 self._plotter.save(filename,orientation) 525 529 return 526 530 … … 614 618 polmode.append("circular") 615 619 else: 616 "Pol type '%s' not valid" %i620 print "Pol type '%s' not valid" %i 617 621 return 618 622 elif 0 > i >= n:
Note:
See TracChangeset
for help on using the changeset viewer.