CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
matplotRender.py
Go to the documentation of this file.
1 '''
2 This module is graphical API using pymatplotlib.
3 Specs:
4 -- We use matplotlib OO class level api, we do not use its high-level helper modules. Favor endured stability over simplicity.
5 -- use TkAgg for interactive mode. Beaware of Tk,pyTk installation defects in various cern distributions.
6 -- PNG as default batch file format
7 -- we support http mode by sending string buf via meme type image/png. Sending a premade static plot to webserver is considered a uploading process instead of http dynamic graphical mode. Therefore covered in this module.
8 '''
9 import sys,os
10 import numpy,datetime
11 import matplotlib
12 from RecoLuminosity.LumiDB import CommonUtil
13 
14 batchonly=False
15 if not os.environ.has_key('DISPLAY') or not os.environ['DISPLAY']:
16  batchonly=True
17  matplotlib.use('Agg',warn=False)
18  from matplotlib.backends.backend_agg import FigureCanvasAgg as CanvasBackend
19 else:
20  try:
21  matplotlib.use('TkAgg',warn=False)
22  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as CanvasBackend
23  from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
24  import Tkinter as Tk
25  root=Tk.Tk()
26  root.wm_title("Lumi GUI in TK")
27  except ImportError:
28  print 'unable to import GUI backend, switch to batch only mode'
29  matplotlib.use('Agg',warn=False)
30  from matplotlib.backends.backend_agg import FigureCanvasAgg as CanvasBackend
31  batchonly=True
32 
33 from matplotlib.figure import Figure
34 from matplotlib.font_manager import fontManager,FontProperties
35 matplotlib.rcParams['lines.linewidth']=1.5
36 matplotlib.rcParams['grid.linewidth']=0.2
37 matplotlib.rcParams['xtick.labelsize']=11
38 matplotlib.rcParams['ytick.labelsize']=11
39 matplotlib.rcParams['legend.fontsize']=10
40 matplotlib.rcParams['axes.labelsize']=11
41 matplotlib.rcParams['font.weight']=567
42 def destroy(e) :
43  sys.exit()
44 
45 class matplotRender():
46  def __init__(self,fig):
47  self.__fig=fig
48  self.__canvas=''
49  self.colormap={}
50  self.colormap['Delivered']='r'
51  self.colormap['Recorded']='b'
52  self.colormap['Effective']='g'
53  self.colormap['Max Inst']='r'
54 
55  def plotSumX_Run(self,rawxdata,rawydata,nticks=6,yscale='linear'):
56  xpoints=[]
57  ypoints={}
58  ytotal={}
59  xidx=[]
60  #print 'max rawxdata ',max(rawxdata)
61  #print 'min rawxdata ',min(rawxdata)
62  for x in CommonUtil.inclusiveRange(min(rawxdata),max(rawxdata),1):
63  #print 'x : ',x
64  xpoints.append(x)
65  xidx.append(rawxdata.index(x)) #get the index of the sample points
66  #print 'xidx : ',rawxdata.index(x)
67  if len(xpoints)==0:
68  print '[WARNING]: no data, do nothing'
69  return
70  t=sum(rawydata['Delivered'])
71  denomitor=1.0
72  unitstring='$\mu$b$^{-1}$'
73  if t>=1.0e3 and t<1.0e06:
74  denomitor=1.0e3
75  unitstring='nb$^{-1}$'
76  elif t>=1.0e6 and t<1.0e9:
77  denomitor=1.0e6
78  unitstring='pb$^{-1}$'
79  elif t>=1.0e9 and t<1.0e12:
80  denomitor=1.0e9
81  unitstring='fb$^{-1}$'
82  elif t>=1.0e12 and t<1.0e15:
83  denomitor=1.0e12
84  unitstring='ab$^{-1}$'
85  for ylabel,yvalues in rawydata.items():
86  ypoints[ylabel]=[]
87  for i in xidx:
88  ypoints[ylabel].append(sum(yvalues[0:i])/denomitor)
89  ytotal[ylabel]=sum(yvalues)/denomitor
90  ax=self.__fig.add_subplot(111)
91  if yscale=='linear':
92  ax.set_yscale('linear')
93  elif yscale=='log':
94  ax.set_yscale('log')
95  else:
96  raise 'unsupported yscale ',yscale
97  ax.set_xlabel(r'Run',position=(0.95,0))
98  ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
99  xticklabels=ax.get_xticklabels()
100  for tx in xticklabels:
101  tx.set_rotation(30)
102  majorLocator=matplotlib.ticker.LinearLocator( nticks )
103  majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
104  minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks)
105  ax.xaxis.set_major_locator(majorLocator)
106  ax.xaxis.set_major_formatter(majorFormatter)
107  ax.xaxis.set_minor_locator(minorLocator)
108  ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
109  ax.grid(True)
110  keylist=ypoints.keys()
111  keylist.sort()
112  legendlist=[]
113  for ylabel in keylist:
114  cl='k'
115  if self.colormap.has_key(ylabel):
116  cl=self.colormap[ylabel]
117  ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
118  legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
119  #font=FontProperties(size='medium',weight='demibold')
120  #annotations
121  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
122  ax.text(xpoints[0],1.025,str(xpoints[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
123  ax.text(xpoints[-1],1.025,str(xpoints[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
124  ax.legend(tuple(legendlist),loc='upper left')
125  self.__fig.subplots_adjust(bottom=0.18,left=0.1)
126 
127  def plotSumX_Fill(self,rawxdata,rawydata,rawfillDict,nticks=6,yscale='linear'):
128  #print 'plotSumX_Fill rawxdata ',rawxdata
129  ytotal={}
130  ypoints={}
131  xpoints=rawfillDict.keys()
132  if len(xpoints)==0:
133  print '[WARNING]: no data, do nothing'
134  return
135  xpoints.sort()
136  beginfo=''
137  endinfo=''
138  t=sum(rawydata['Delivered'])
139  denomitor=1.0
140  unitstring='$\mu$b$^{-1}$'
141  if t>=1.0e3 and t<1.0e06:
142  denomitor=1.0e3
143  unitstring='nb$^{-1}$'
144  elif t>=1.0e6 and t<1.0e9:
145  denomitor=1.0e6
146  unitstring='pb$^{-1}$'
147  elif t>=1.0e9 and t<1.0e12:
148  denomitor=1.0e9
149  unitstring='fb$^{-1}$'
150  elif t>=1.0e12 and t<1.0e15:
151  denomitor=1.0e12
152  unitstring='ab$^{-1}$'
153 
154  for ylabel,yvalue in rawydata.items():
155  ypoints[ylabel]=[]
156  ytotal[ylabel]=sum(rawydata[ylabel])/denomitor
157  for idx,fill in enumerate(xpoints):
158  runlist=rawfillDict[fill]
159  if idx==0:
160  beginfo=str(fill)+':'+str(runlist[0])
161  if idx==len(xpoints)-1:
162  endinfo=str(fill)+':'+str(runlist[-1])
163  xidx=rawxdata.index(max(runlist))
164  ypoints[ylabel].append(sum(yvalue[0:xidx])/denomitor)
165  ax=self.__fig.add_subplot(111)
166  ax.set_xlabel(r'LHC Fill Number',position=(0.84,0))
167  ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
168  ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
169  if yscale=='linear':
170  ax.set_yscale('linear')
171  elif yscale=='log':
172  ax.set_yscale('log')
173  else:
174  raise 'unsupported yscale ',yscale
175  xticklabels=ax.get_xticklabels()
176  majorLocator=matplotlib.ticker.LinearLocator( nticks )
177  majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
178  #minorLocator=matplotlib.ticker.MultipleLocator(sampleinterval)
179  ax.xaxis.set_major_locator(majorLocator)
180  ax.xaxis.set_major_formatter(majorFormatter)
181  #ax.xaxis.set_minor_locator(minorLocator)
182  ax.grid(True)
183  keylist=ypoints.keys()
184  keylist.sort()
185  legendlist=[]
186  for ylabel in keylist:
187  cl='k'
188  if self.colormap.has_key(ylabel):
189  cl=self.colormap[ylabel]
190  ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
191  legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
192  #font=FontProperties(size='medium',weight='demibold')
193  #annotations
194  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
195  ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
196  ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
197  ax.legend(tuple(legendlist),loc='upper left')
198  self.__fig.subplots_adjust(bottom=0.1,left=0.1)
199 
200  def plotSumX_Time(self,rawxdata,rawydata,minTime,maxTime,hltpath='',nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
201  '''
202  input:
203  rawxdata runDict{runnumber:[delivered,recorded,recorded_hltpath]}
204  rawydata {label:[rundata]}
205  '''
206  xpoints=[]
207  ypoints={}
208  ytotal={}
209  xidx=[]
210  runs=rawxdata.keys()
211  runs.sort()
212  for idx,run in enumerate(runs):
213  xpoints.append(matplotlib.dates.date2num(rawxdata[run][0]))
214  xidx.append(idx)
215  if len(xpoints)==0:
216  print '[WARNING]: no data, do nothing'
217  return
218  t=sum(rawydata['Delivered'])
219  denomitor=1.0
220  unitstring='$\mu$b$^{-1}$'
221  if t>=1.0e3 and t<1.0e06:
222  denomitor=1.0e3
223  unitstring='nb$^{-1}$'
224  elif t>=1.0e6 and t<1.0e9:
225  denomitor=1.0e6
226  unitstring='pb$^{-1}$'
227  elif t>=1.0e9 and t<1.0e12:
228  denomitor=1.0e9
229  unitstring='fb$^{-1}$'
230  elif t>=1.0e12 and t<1.0e15:
231  denomitor=1.0e12
232  unitstring='ab$^{-1}$'
233 
234  for ylabel,yvalue in rawydata.items():
235  ypoints[ylabel]=[]
236  for i in xidx:
237  ypoints[ylabel].append(sum(yvalue[0:i])/denomitor)
238  ytotal[ylabel]=sum(yvalue)/denomitor
239  ax=self.__fig.add_subplot(111)
240  if yscale=='linear':
241  ax.set_yscale('linear')
242  elif yscale=='log':
243  ax.set_yscale('log')
244  else:
245  raise 'unsupported yscale ',yscale
246  dateFmt=matplotlib.dates.DateFormatter('%d/%m')
247  majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
248  ax.xaxis.set_major_locator(majorLoc)
249  minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
250  ax.xaxis.set_major_formatter(dateFmt)
251  ax.set_xlabel(r'Date',position=(0.84,0))
252  ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
253  ax.xaxis.set_minor_locator(minorLoc)
254  ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
255  xticklabels=ax.get_xticklabels()
256  for tx in xticklabels:
257  tx.set_horizontalalignment('left')
258  ax.grid(True)
259  keylist=ypoints.keys()
260  keylist.sort()
261  legendlist=[]
262  for ylabel in keylist:
263  cl='k'
264  if self.colormap.has_key(ylabel):
265  cl=self.colormap[ylabel]
266  ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
267  legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
268  #annotations
269  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
270  #print 'run boundary ',runs[0],runs[-1]
271  #print 'xpoints boundary ',xpoints[0],xpoints[-1]
272  if annotateBoundaryRunnum:
273  ax.text(xpoints[0],1.025,str(runs[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
274  ax.text(xpoints[-1],1.025,str(runs[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
275  yearStr=minTime.strftime('%Y')
276  firstimeStr=minTime.strftime('%b %d %H:%M')
277  lasttimeStr=maxTime.strftime('%b %d %H:%M')
278  ax.set_title('Total Integrated Luminosity '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
279  ax.legend(tuple(legendlist),loc='upper left')
280  self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
281  self.__fig.subplots_adjust(bottom=0.1,left=0.1)
282 
283  def plotPerdayX_Time(self,days,databyday,minTime,maxTime,boundaryInfo=[],nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
284  '''input
285  databyday {'Delivered':[lumiperday]}
286  boundaryInfo [[begintime,begininfo],[endtime,endinfo]]
287  '''
288  ax=self.__fig.add_subplot(111)
289  t=max(databyday['Delivered'])
290  minvar=min([x for x in databyday['Recorded'] if x>0]) #used only for log scale
291  maxvalues={}
292  keylist=databyday.keys()
293  keylist.sort()
294  for k in keylist:
295  maxvalues[k]=max(databyday[k])
296 
297  if yscale=='linear':
298  ax.set_yscale('linear')
299  elif yscale=='log':
300  ax.set_yscale('log')
301  for k in keylist:
302  for i,v in enumerate(databyday[k]):
303  if v<minvar:
304  databyday[k][i]=minvar
305  else:
306  raise 'unsupported yscale ',yscale
307  dateFmt=matplotlib.dates.DateFormatter('%d/%m')
308  majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
309  minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
310  ax.xaxis.set_major_formatter(dateFmt)
311  ax.set_xlabel(r'Date',position=(0.84,0))
312  ax.xaxis.set_major_locator(majorLoc)
313  ax.xaxis.set_minor_locator(minorLoc)
314  xticklabels=ax.get_xticklabels()
315  for tx in xticklabels:
316  tx.set_horizontalalignment('right')
317  ax.grid(True)
318  legendlist=[]
319 
320  denomitor=1.0
321  unitstring='$\mu$b$^{-1}$'
322  if t>=1.0e3 and t<1.0e06:
323  denomitor=1.0e3
324  unitstring='nb$^{-1}$'
325  elif t>=1.0e6 and t<1.0e9:
326  denomitor=1.0e6
327  unitstring='pb$^{-1}$'
328  elif t>=1.0e9 and t<1.0e12:
329  denomitor=1.0e9
330  unitstring='fb$^{-1}$'
331  elif t>=1.0e12 and t<1.0e15:
332  denomitor=1.0e12
333  unitstring='ab$^{-1}$'
334 
335  ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
336  for ylabel in keylist:
337  cl='k'
338  if self.colormap.has_key(ylabel):
339  cl=self.colormap[ylabel]
340  ax.plot(days,[y/denomitor for y in databyday[ylabel]],label=ylabel,color=cl,drawstyle='steps')
341  legendlist.append(ylabel+' Max '+'%.2f'%(maxvalues[ylabel]/denomitor)+' '+unitstring)
342  ax.legend(tuple(legendlist),loc='upper left')
343  ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
344  if annotateBoundaryRunnum:
345  if len(boundaryInfo)!=0:
346  begtime=boundaryInfo[0][0]
347  beginfo=boundaryInfo[0][1]
348  endtime=boundaryInfo[1][0]
349  endinfo=boundaryInfo[1][1]
350  #annotations
351  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
352  ax.text(matplotlib.dates.date2num(begtime),1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
353  ax.text(matplotlib.dates.date2num(endtime),1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
354  yearStr=minTime.strftime('%Y')
355  firstimeStr=minTime.strftime('%b %d %H:%M')
356  lasttimeStr=maxTime.strftime('%b %d %H:%M')
357  ax.set_title('Integrated Luminosity/Day '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
358  self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
359  self.__fig.subplots_adjust(bottom=0.18,left=0.1)
360 
361  def plotPeakPerday_Time(self,daydict,minTime,maxTime,nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
362  '''
363  Input: daydict={}#{day:[run,lsnum,instlumi]}
364  '''
365  xpoints=[]
366  ypoints=[]
367  legendlist=[]
368  days=daydict.keys()
369  days.sort()
370  beginfo=str(daydict[days[0]][0])+':'+str(daydict[days[0]][1])
371  endinfo=str(daydict[days[-1]][0])+':'+str(daydict[days[-1]][1])
372  maxinfo=''
373  ymax=0.0
374  xmax=0
375  minday=days[0]
376  maxday=days[-1]
377  minvar=0.1
378  for day in range(minday,maxday+1):
379  xpoints.append(day)
380  if not daydict.has_key(day):
381  ypoints.append(0.0)
382  continue
383  daymaxdata=daydict[day]
384  ypoints.append(daymaxdata[2])
385  if daydict[day][2]>ymax:
386  ymax=daydict[day][2]
387  xmax=day
388  runmax=daydict[day][0]
389  lsmax=daydict[day][1]
390  maxinfo=str(runmax)+':'+str(lsmax)
391  denomitor=1.0
392  unitstring='$\mu$b$^{-1}$s$^{-1}$'
393  if ymax>=1.0e3 and ymax<1.0e06:
394  denomitor=1.0e3
395  unitstring='nb$^{-1}$s$^{-1}$'
396  elif ymax>=1.0e6 and ymax<1.0e9:
397  denomitor=1.0e6
398  unitstring='pb$^{-1}$s$^{-1}$'
399  elif ymax>=1.0e9 and ymax<1.0e12:
400  denomitor=1.0e9
401  unitstring='fb$^{-1}$s$^{-1}$'
402  elif ymax>=1.0e12 and ymax<1.0e15:
403  denomitor=1.0e12
404  unitstring='ab$^{-1}$s$^{-1}$'
405 
406  ax=self.__fig.add_subplot(111)
407  if yscale=='linear':
408  ax.set_yscale('linear')
409  elif yscale=='log':
410  ax.set_yscale('log')
411  for i,v in enumerate(ypoints):
412  if v<minvar:
413  ypoints[i]=minvar
414  else:
415  raise 'unsupported yscale ',yscale
416  dateFmt=matplotlib.dates.DateFormatter('%d/%m')
417  majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
418  minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
419  ax.xaxis.set_major_formatter(dateFmt)
420  ax.set_xlabel(r'Date',position=(0.84,0))
421  ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
422  ax.xaxis.set_major_locator(majorLoc)
423  ax.xaxis.set_minor_locator(minorLoc)
424  xticklabels=ax.get_xticklabels()
425  for tx in xticklabels:
426  tx.set_horizontalalignment('right')
427  ax.grid(True)
428  cl=self.colormap['Max Inst']
429  #print 'xpoints ',xpoints
430  #print 'ypoints ',ypoints
431  #print 'maxinfo ',maxinfo
432  #print 'beginfo ',beginfo
433  #print 'endinfo ',endinfo
434  ax.plot(xpoints,[y/denomitor for y in ypoints],label='Max Inst',color=cl,drawstyle='steps')
435  legendlist.append('Max Inst %.2f'%(ymax/denomitor)+' '+unitstring)
436  ax.legend(tuple(legendlist),loc='upper left')
437  ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
438  if annotateBoundaryRunnum:
439  #annotations
440  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
441  ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
442  ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
443  ax.annotate(maxinfo,xy=(xmax,ymax),xycoords='data',xytext=(0,13),textcoords='offset points',arrowprops=dict(facecolor='green',shrink=0.05),size='x-small',horizontalalignment='center',color='green',bbox=dict(facecolor='white'))
444  yearStr=minTime.strftime('%Y')
445  firstimeStr=minTime.strftime('%b %d %H:%M')
446  lasttimeStr=maxTime.strftime('%b %d %H:%M')
447  ax.set_title('Peak Luminosity/Day '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
448  self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
449  self.__fig.subplots_adjust(bottom=0.1,left=0.1)
450 
451  def plotInst_RunLS(self,rawxdata,rawydata,nticks=6):
452  '''
453  Input: rawxdata [run,fill,norbit,starttime,stoptime,totalls,ncmsls]
454  rawydata {label:[instlumi]}
455  '''
456  runnum=rawxdata[0]
457  fill=rawxdata[1]
458  norbit=rawxdata[2]
459  starttime=rawxdata[3]
460  stoptime=rawxdata[4]
461  totalls=rawxdata[-2]
462  ncmsls=rawxdata[-1]
463  peakinst=max(rawydata['Delivered'])
464  lslength=float(norbit)*3564*25.0e-9
465  totaldelivered=sum(rawydata['Delivered'])*lslength
466  totalrecorded=sum(rawydata['Recorded'])*lslength
467  xpoints=range(1,totalls+1)
468  #print len(xpoints)
469  ypoints={}
470  ymax={}
471  for ylabel,yvalue in rawydata.items():
472  ypoints[ylabel]=yvalue
473  ymax[ylabel]=max(yvalue)
474  left=0.15
475  width=0.7
476  bottom=0.1
477  height=0.65
478  bottom_h=bottom+height
479  rect_scatter=[left,bottom,width,height]
480  rect_table=[left,bottom_h,width,0.25]
481 
482  nullfmt=matplotlib.ticker.NullFormatter()
483  nullloc=matplotlib.ticker.NullLocator()
484  axtab=self.__fig.add_axes(rect_table,frameon=False)
485  axtab.set_axis_off()
486  axtab.xaxis.set_major_formatter(nullfmt)
487  axtab.yaxis.set_major_formatter(nullfmt)
488  axtab.xaxis.set_major_locator(nullloc)
489  axtab.yaxis.set_major_locator(nullloc)
490 
491  ax=self.__fig.add_axes(rect_scatter)
492 
493  majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
494  minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
495  ax.set_xlabel(r'LS',position=(0.96,0))
496  ax.set_ylabel(r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9))
497  ax.xaxis.set_major_locator(majorLoc)
498  ax.xaxis.set_minor_locator(minorLoc)
499  ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
500  xticklabels=ax.get_xticklabels()
501  for tx in xticklabels:
502  tx.set_horizontalalignment('right')
503  ax.grid(True)
504  keylist=ypoints.keys()
505  keylist.sort()
506  legendlist=[]
507 
508  for ylabel in keylist:
509  cl='k'
510  if self.colormap.has_key(ylabel):
511  cl=self.colormap[ylabel]
512  ax.plot(xpoints,ypoints[ylabel],'.',label=ylabel,color=cl)
513  legendlist.append(ylabel)
514  #ax.axhline(0,color='green',linewidth=0.2)
515  ax.axvline(xpoints[ncmsls-1],color='green',linewidth=0.2)
516 
517  denomitor=1.0
518  unitstring='/$\mu$b'
519  if totaldelivered>=1.0e3 and totaldelivered<1.0e06:
520  denomitor=1.0e3
521  unitstring='/nb'
522  elif totaldelivered>=1.0e6 and totaldelivered<1.0e9:
523  denomitor=1.0e6
524  unitstring='/pb'
525  elif totaldelivered>=1.0e9 and totaldelivered<1.0e12:
526  denomitor=1.0e9
527  unitstring='/fb'
528  elif totaldelivered>=1.0e12 and totaldelivered<1.0e15:
529  denomitor=1.0e12
530  unitstring='/ab'
531  colLabels=('run','fill','max inst(/$\mu$b/s)','delivered('+unitstring+')','recorded('+unitstring+')')
532  cellText=[[str(runnum),str(fill),'%.3f'%(peakinst),'%.3f'%(totaldelivered/denomitor),'%.3f'%(totalrecorded/denomitor)]]
533 
534  sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc='center',loc='center')
535  trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
536  axtab.add_table(sumtable)
537 
538  ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
539  ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
540  ax.legend(tuple(legendlist),loc='upper right',numpoints=1)
541 
542  def drawHTTPstring(self):
543  self.__canvas=CanvasBackend(self.__fig)
544  cherrypy.response.headers['Content-Type']='image/png'
545  buf=StringIO()
546  self.__canvas.print_png(buf)
547  return buf.getvalue()
548 
549  def drawPNG(self,filename):
550  self.__canvas=CanvasBackend(self.__fig)
551  self.__canvas.print_figure(filename)
552 
553  def drawInteractive(self):
554  if batchonly:
555  print 'interactive mode is not available for your setup, exit'
556  sys.exit()
557  self.__canvas=CanvasBackend(self.__fig,master=root)
558  self.__canvas.show()
559  self.__canvas.get_tk_widget().pack(side=Tk.TOP,fill=Tk.BOTH,expand=1)
560  toolbar=NavigationToolbar2TkAgg(self.__canvas,root)
561  toolbar.update()
562  self.__canvas._tkcanvas.pack(side=Tk.TOP,fill=Tk.BOTH,expand=1)
563  button = Tk.Button(master=root,text='Quit',command=sys.exit)
564  button.pack(side=Tk.BOTTOM)
565  Tk.mainloop()
566 if __name__=='__main__':
567  fig=Figure(figsize=(5,5),dpi=100)
568  a=fig.add_subplot(111)
569  t=numpy.arange(0.0,3.0,0.01)
570  s=numpy.sin(2*numpy.pi*t)
571  a.plot(t,s)
573  m.drawPNG('testmatplotrender.png')
574  m.drawInteractive()
575  #print drawHTTPstring()
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
def inclusiveRange
Definition: CommonUtil.py:95