CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoLuminosity/LumiDB/python/matplotRender.py

Go to the documentation of this file.
00001 '''
00002 This module is graphical API using pymatplotlib.
00003 Specs:
00004 -- We use matplotlib OO class level api, we do not use its high-level helper modules. Favor endured stability over simplicity. 
00005 -- use TkAgg for interactive mode. Beaware of Tk,pyTk installation defects in various cern distributions.
00006 -- PNG as default batch file format
00007 -- 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.
00008 '''
00009 import sys,os
00010 import numpy,datetime
00011 import matplotlib
00012 from RecoLuminosity.LumiDB import CommonUtil
00013 
00014 batchonly=False
00015 if not os.environ.has_key('DISPLAY') or not os.environ['DISPLAY']:
00016     batchonly=True
00017     matplotlib.use('Agg',warn=False)
00018     from matplotlib.backends.backend_agg import FigureCanvasAgg as CanvasBackend
00019 else:
00020     try:
00021         matplotlib.use('TkAgg',warn=False)
00022         from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as CanvasBackend
00023         from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
00024         import Tkinter as Tk
00025         root=Tk.Tk()
00026         root.wm_title("Lumi GUI in TK")
00027     except ImportError:
00028         print 'unable to import GUI backend, switch to batch only mode'
00029         matplotlib.use('Agg',warn=False)
00030         from matplotlib.backends.backend_agg import FigureCanvasAgg as CanvasBackend
00031         batchonly=True
00032 
00033 from matplotlib.figure import Figure
00034 from matplotlib.font_manager import fontManager,FontProperties
00035 matplotlib.rcParams['lines.linewidth']=1.5
00036 matplotlib.rcParams['grid.linewidth']=0.2
00037 matplotlib.rcParams['xtick.labelsize']=11
00038 matplotlib.rcParams['ytick.labelsize']=11
00039 matplotlib.rcParams['legend.fontsize']=10
00040 matplotlib.rcParams['axes.labelsize']=11
00041 matplotlib.rcParams['font.weight']=567
00042 def destroy(e) :
00043     sys.exit()
00044     
00045 class matplotRender():
00046     def __init__(self,fig):
00047         self.__fig=fig
00048         self.__canvas=''
00049         self.colormap={}
00050         self.colormap['Delivered']='r'
00051         self.colormap['Recorded']='b'
00052         self.colormap['Effective']='g'
00053         self.colormap['Max Inst']='r'
00054 
00055     def plotSumX_Run(self,rawxdata,rawydata,nticks=6,yscale='linear'):
00056         xpoints=[]
00057         ypoints={}
00058         ytotal={}
00059         xidx=[]
00060         #print 'max rawxdata ',max(rawxdata)
00061         #print 'min rawxdata ',min(rawxdata)
00062         for x in CommonUtil.inclusiveRange(min(rawxdata),max(rawxdata),1):
00063             #print 'x : ',x
00064             xpoints.append(x)
00065             xidx.append(rawxdata.index(x)) #get the index of the sample points
00066             #print 'xidx : ',rawxdata.index(x)
00067         if len(xpoints)==0:
00068             print '[WARNING]: no data, do nothing'
00069             return
00070         t=sum(rawydata['Delivered'])
00071         denomitor=1.0
00072         unitstring='$\mu$b$^{-1}$'
00073         if t>=1.0e3 and t<1.0e06:
00074             denomitor=1.0e3
00075             unitstring='nb$^{-1}$'
00076         elif t>=1.0e6 and t<1.0e9:
00077             denomitor=1.0e6
00078             unitstring='pb$^{-1}$'
00079         elif t>=1.0e9 and t<1.0e12:
00080             denomitor=1.0e9
00081             unitstring='fb$^{-1}$'
00082         elif  t>=1.0e12 and t<1.0e15:
00083             denomitor=1.0e12
00084             unitstring='ab$^{-1}$'
00085         for ylabel,yvalues in rawydata.items():
00086             ypoints[ylabel]=[]           
00087             for i in xidx:
00088                 ypoints[ylabel].append(sum(yvalues[0:i])/denomitor)
00089             ytotal[ylabel]=sum(yvalues)/denomitor  
00090         ax=self.__fig.add_subplot(111)
00091         if yscale=='linear':
00092             ax.set_yscale('linear')
00093         elif yscale=='log':
00094             ax.set_yscale('log')
00095         else:
00096             raise 'unsupported yscale ',yscale
00097         ax.set_xlabel(r'Run',position=(0.95,0))
00098         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00099         xticklabels=ax.get_xticklabels()
00100         for tx in xticklabels:
00101             tx.set_rotation(30)
00102         majorLocator=matplotlib.ticker.LinearLocator( nticks )
00103         majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
00104         minorLocator=matplotlib.ticker.LinearLocator(numticks=4*nticks)
00105         ax.xaxis.set_major_locator(majorLocator)
00106         ax.xaxis.set_major_formatter(majorFormatter)
00107         ax.xaxis.set_minor_locator(minorLocator)
00108         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00109         ax.grid(True)
00110         keylist=ypoints.keys()
00111         keylist.sort()
00112         legendlist=[]
00113         for ylabel in keylist:
00114             cl='k'
00115             if self.colormap.has_key(ylabel):
00116                 cl=self.colormap[ylabel]
00117             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00118             legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
00119         #font=FontProperties(size='medium',weight='demibold')
00120         #annotations
00121         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00122         ax.text(xpoints[0],1.025,str(xpoints[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00123         ax.text(xpoints[-1],1.025,str(xpoints[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00124         ax.legend(tuple(legendlist),loc='upper left')
00125         self.__fig.subplots_adjust(bottom=0.18,left=0.1)
00126         
00127     def plotSumX_Fill(self,rawxdata,rawydata,rawfillDict,nticks=6,yscale='linear'):
00128         #print 'plotSumX_Fill rawxdata ',rawxdata
00129         ytotal={}
00130         ypoints={}
00131         xpoints=rawfillDict.keys()
00132         if len(xpoints)==0:
00133             print '[WARNING]: no data, do nothing'
00134             return
00135         xpoints.sort()
00136         beginfo=''
00137         endinfo=''
00138         t=sum(rawydata['Delivered'])
00139         denomitor=1.0
00140         unitstring='$\mu$b$^{-1}$'
00141         if t>=1.0e3 and t<1.0e06:
00142             denomitor=1.0e3
00143             unitstring='nb$^{-1}$'
00144         elif t>=1.0e6 and t<1.0e9:
00145             denomitor=1.0e6
00146             unitstring='pb$^{-1}$'
00147         elif t>=1.0e9 and t<1.0e12:
00148             denomitor=1.0e9
00149             unitstring='fb$^{-1}$'
00150         elif  t>=1.0e12 and t<1.0e15:
00151             denomitor=1.0e12
00152             unitstring='ab$^{-1}$'
00153             
00154         for ylabel,yvalue in rawydata.items():
00155             ypoints[ylabel]=[]
00156             ytotal[ylabel]=sum(rawydata[ylabel])/denomitor
00157             for idx,fill in enumerate(xpoints):
00158                 runlist=rawfillDict[fill]
00159                 if idx==0:
00160                     beginfo=str(fill)+':'+str(runlist[0])
00161                 if idx==len(xpoints)-1:
00162                     endinfo=str(fill)+':'+str(runlist[-1])
00163                 xidx=rawxdata.index(max(runlist))
00164                 ypoints[ylabel].append(sum(yvalue[0:xidx])/denomitor)
00165         ax=self.__fig.add_subplot(111)
00166         ax.set_xlabel(r'LHC Fill Number',position=(0.84,0))
00167         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00168         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00169         if yscale=='linear':
00170             ax.set_yscale('linear')
00171         elif yscale=='log':
00172             ax.set_yscale('log')
00173         else:
00174             raise 'unsupported yscale ',yscale
00175         xticklabels=ax.get_xticklabels()
00176         majorLocator=matplotlib.ticker.LinearLocator( nticks )
00177         majorFormatter=matplotlib.ticker.FormatStrFormatter('%d')
00178         #minorLocator=matplotlib.ticker.MultipleLocator(sampleinterval)
00179         ax.xaxis.set_major_locator(majorLocator)
00180         ax.xaxis.set_major_formatter(majorFormatter)
00181         #ax.xaxis.set_minor_locator(minorLocator)
00182         ax.grid(True)
00183         keylist=ypoints.keys()
00184         keylist.sort()
00185         legendlist=[]
00186         for ylabel in keylist:
00187             cl='k'
00188             if self.colormap.has_key(ylabel):
00189                 cl=self.colormap[ylabel]
00190             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00191             legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
00192         #font=FontProperties(size='medium',weight='demibold')
00193         #annotations
00194         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00195         ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00196         ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00197         ax.legend(tuple(legendlist),loc='upper left')
00198         self.__fig.subplots_adjust(bottom=0.1,left=0.1)
00199         
00200     def plotSumX_Time(self,rawxdata,rawydata,minTime,maxTime,hltpath='',nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
00201         '''
00202         input:
00203            rawxdata runDict{runnumber:[delivered,recorded,recorded_hltpath]}
00204            rawydata {label:[rundata]}
00205         '''
00206         xpoints=[]
00207         ypoints={}
00208         ytotal={}
00209         xidx=[]
00210         runs=rawxdata.keys()
00211         runs.sort()
00212         for idx,run in enumerate(runs):
00213             xpoints.append(matplotlib.dates.date2num(rawxdata[run][0]))
00214             xidx.append(idx)
00215         if len(xpoints)==0:
00216             print '[WARNING]: no data, do nothing'
00217             return
00218         t=sum(rawydata['Delivered'])
00219         denomitor=1.0
00220         unitstring='$\mu$b$^{-1}$'
00221         if t>=1.0e3 and t<1.0e06:
00222             denomitor=1.0e3
00223             unitstring='nb$^{-1}$'
00224         elif t>=1.0e6 and t<1.0e9:
00225             denomitor=1.0e6
00226             unitstring='pb$^{-1}$'
00227         elif t>=1.0e9 and t<1.0e12:
00228             denomitor=1.0e9
00229             unitstring='fb$^{-1}$'
00230         elif  t>=1.0e12 and t<1.0e15:
00231             denomitor=1.0e12
00232             unitstring='ab$^{-1}$'
00233             
00234         for ylabel,yvalue in rawydata.items():
00235             ypoints[ylabel]=[]
00236             for i in xidx:
00237                 ypoints[ylabel].append(sum(yvalue[0:i])/denomitor)
00238             ytotal[ylabel]=sum(yvalue)/denomitor
00239         ax=self.__fig.add_subplot(111)
00240         if yscale=='linear':
00241             ax.set_yscale('linear')
00242         elif yscale=='log':
00243             ax.set_yscale('log')
00244         else:
00245             raise 'unsupported yscale ',yscale
00246         dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00247         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00248         ax.xaxis.set_major_locator(majorLoc)
00249         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00250         ax.xaxis.set_major_formatter(dateFmt)
00251         ax.set_xlabel(r'Date',position=(0.84,0))
00252         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00253         ax.xaxis.set_minor_locator(minorLoc)
00254         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00255         xticklabels=ax.get_xticklabels()
00256         for tx in xticklabels:
00257             tx.set_horizontalalignment('left')
00258         ax.grid(True)
00259         keylist=ypoints.keys()
00260         keylist.sort()
00261         legendlist=[]
00262         for ylabel in keylist:
00263             cl='k'
00264             if self.colormap.has_key(ylabel):
00265                 cl=self.colormap[ylabel]
00266             ax.plot(xpoints,ypoints[ylabel],label=ylabel,color=cl,drawstyle='steps')
00267             legendlist.append(ylabel+' '+'%.2f'%(ytotal[ylabel])+' '+unitstring)
00268         #annotations
00269         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00270         #print 'run boundary ',runs[0],runs[-1]
00271         #print 'xpoints boundary ',xpoints[0],xpoints[-1]
00272         if annotateBoundaryRunnum:
00273             ax.text(xpoints[0],1.025,str(runs[0]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00274             ax.text(xpoints[-1],1.025,str(runs[-1]),transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00275         yearStr=minTime.strftime('%Y')
00276         firstimeStr=minTime.strftime('%b %d %H:%M')
00277         lasttimeStr=maxTime.strftime('%b %d %H:%M')
00278         ax.set_title('Total Integrated Luminosity '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
00279         ax.legend(tuple(legendlist),loc='upper left')
00280         self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
00281         self.__fig.subplots_adjust(bottom=0.1,left=0.1)
00282         
00283     def plotPerdayX_Time(self,days,databyday,minTime,maxTime,boundaryInfo=[],nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
00284         '''input
00285             databyday {'Delivered':[lumiperday]}
00286             boundaryInfo [[begintime,begininfo],[endtime,endinfo]]
00287         '''
00288         ax=self.__fig.add_subplot(111)
00289         t=max(databyday['Delivered'])
00290         minvar=min([x for x in databyday['Recorded'] if x>0]) #used only for log scale
00291         maxvalues={}
00292         keylist=databyday.keys()
00293         keylist.sort()
00294         for k in keylist:
00295             maxvalues[k]=max(databyday[k])
00296             
00297         if yscale=='linear':
00298             ax.set_yscale('linear')
00299         elif yscale=='log':
00300             ax.set_yscale('log')
00301             for k in keylist:
00302                 for i,v in enumerate(databyday[k]):
00303                     if v<minvar:
00304                         databyday[k][i]=minvar
00305         else:
00306             raise 'unsupported yscale ',yscale
00307         dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00308         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00309         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00310         ax.xaxis.set_major_formatter(dateFmt)
00311         ax.set_xlabel(r'Date',position=(0.84,0))
00312         ax.xaxis.set_major_locator(majorLoc)
00313         ax.xaxis.set_minor_locator(minorLoc)
00314         xticklabels=ax.get_xticklabels()
00315         for tx in xticklabels:
00316             tx.set_horizontalalignment('right')
00317         ax.grid(True)
00318         legendlist=[]
00319      
00320         denomitor=1.0
00321         unitstring='$\mu$b$^{-1}$'
00322         if t>=1.0e3 and t<1.0e06:
00323             denomitor=1.0e3
00324             unitstring='nb$^{-1}$'
00325         elif t>=1.0e6 and t<1.0e9:
00326             denomitor=1.0e6
00327             unitstring='pb$^{-1}$'
00328         elif t>=1.0e9 and t<1.0e12:
00329             denomitor=1.0e9
00330             unitstring='fb$^{-1}$'
00331         elif  t>=1.0e12 and t<1.0e15:
00332             denomitor=1.0e12
00333             unitstring='ab$^{-1}$'
00334 
00335         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))    
00336         for ylabel in keylist:
00337             cl='k'
00338             if self.colormap.has_key(ylabel):
00339                 cl=self.colormap[ylabel]
00340             ax.plot(days,[y/denomitor for y in databyday[ylabel]],label=ylabel,color=cl,drawstyle='steps')
00341             legendlist.append(ylabel+' Max '+'%.2f'%(maxvalues[ylabel]/denomitor)+' '+unitstring)
00342         ax.legend(tuple(legendlist),loc='upper left')
00343         ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
00344         if annotateBoundaryRunnum:
00345             if len(boundaryInfo)!=0:
00346                 begtime=boundaryInfo[0][0]
00347                 beginfo=boundaryInfo[0][1]
00348                 endtime=boundaryInfo[1][0]
00349                 endinfo=boundaryInfo[1][1]
00350                 #annotations
00351                 trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00352                 ax.text(matplotlib.dates.date2num(begtime),1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00353                 ax.text(matplotlib.dates.date2num(endtime),1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00354         yearStr=minTime.strftime('%Y')
00355         firstimeStr=minTime.strftime('%b %d %H:%M')
00356         lasttimeStr=maxTime.strftime('%b %d %H:%M')
00357         ax.set_title('Integrated Luminosity/Day '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
00358         self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
00359         self.__fig.subplots_adjust(bottom=0.18,left=0.1)
00360 
00361     def plotPeakPerday_Time(self,daydict,minTime,maxTime,nticks=6,annotateBoundaryRunnum=False,yscale='linear'):
00362         '''
00363         Input: daydict={}#{day:[run,lsnum,instlumi]}
00364         '''
00365         xpoints=[]
00366         ypoints=[]
00367         legendlist=[]
00368         days=daydict.keys()
00369         days.sort()
00370         beginfo=str(daydict[days[0]][0])+':'+str(daydict[days[0]][1])
00371         endinfo=str(daydict[days[-1]][0])+':'+str(daydict[days[-1]][1])
00372         maxinfo=''
00373         ymax=0.0
00374         xmax=0
00375         minday=days[0]
00376         maxday=days[-1]
00377         minvar=0.1
00378         for day in range(minday,maxday+1):
00379             xpoints.append(day)
00380             if not daydict.has_key(day):
00381                 ypoints.append(0.0)
00382                 continue
00383             daymaxdata=daydict[day]
00384             ypoints.append(daymaxdata[2])
00385             if daydict[day][2]>ymax:
00386                 ymax=daydict[day][2]
00387                 xmax=day
00388                 runmax=daydict[day][0]
00389                 lsmax=daydict[day][1]
00390                 maxinfo=str(runmax)+':'+str(lsmax)
00391         denomitor=1.0
00392         unitstring='$\mu$b$^{-1}$s$^{-1}$'
00393         if ymax>=1.0e3 and ymax<1.0e06:
00394             denomitor=1.0e3
00395             unitstring='nb$^{-1}$s$^{-1}$'
00396         elif ymax>=1.0e6 and ymax<1.0e9:
00397             denomitor=1.0e6
00398             unitstring='pb$^{-1}$s$^{-1}$'
00399         elif ymax>=1.0e9 and ymax<1.0e12:
00400             denomitor=1.0e9
00401             unitstring='fb$^{-1}$s$^{-1}$'
00402         elif ymax>=1.0e12 and ymax<1.0e15:
00403             denomitor=1.0e12
00404             unitstring='ab$^{-1}$s$^{-1}$'
00405             
00406         ax=self.__fig.add_subplot(111)
00407         if yscale=='linear':
00408             ax.set_yscale('linear')
00409         elif yscale=='log':
00410             ax.set_yscale('log')
00411             for i,v in enumerate(ypoints):
00412                     if v<minvar:
00413                         ypoints[i]=minvar
00414         else:
00415             raise 'unsupported yscale ',yscale
00416         dateFmt=matplotlib.dates.DateFormatter('%d/%m')
00417         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00418         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00419         ax.xaxis.set_major_formatter(dateFmt)
00420         ax.set_xlabel(r'Date',position=(0.84,0))
00421         ax.set_ylabel(r'L '+unitstring,position=(0,0.9))
00422         ax.xaxis.set_major_locator(majorLoc)
00423         ax.xaxis.set_minor_locator(minorLoc)
00424         xticklabels=ax.get_xticklabels()
00425         for tx in xticklabels:
00426             tx.set_horizontalalignment('right')
00427         ax.grid(True)
00428         cl=self.colormap['Max Inst']
00429         #print 'xpoints ',xpoints
00430         #print 'ypoints ',ypoints
00431         #print 'maxinfo ',maxinfo
00432         #print 'beginfo ',beginfo
00433         #print 'endinfo ',endinfo
00434         ax.plot(xpoints,[y/denomitor for y in ypoints],label='Max Inst',color=cl,drawstyle='steps')
00435         legendlist.append('Max Inst %.2f'%(ymax/denomitor)+' '+unitstring)
00436         ax.legend(tuple(legendlist),loc='upper left')
00437         ax.set_xbound(lower=matplotlib.dates.date2num(minTime),upper=matplotlib.dates.date2num(maxTime))
00438         if annotateBoundaryRunnum:
00439            #annotations
00440            trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)
00441            ax.text(xpoints[0],1.025,beginfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00442            ax.text(xpoints[-1],1.025,endinfo,transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))
00443            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'))
00444         yearStr=minTime.strftime('%Y')
00445         firstimeStr=minTime.strftime('%b %d %H:%M')
00446         lasttimeStr=maxTime.strftime('%b %d %H:%M')
00447         ax.set_title('Peak Luminosity/Day '+yearStr+' ('+firstimeStr+' UTC - '+lasttimeStr+' UTC)',size='small',family='fantasy')
00448         self.__fig.autofmt_xdate(bottom=0.18,rotation=0)
00449         self.__fig.subplots_adjust(bottom=0.1,left=0.1)
00450 
00451     def plotInst_RunLS(self,rawxdata,rawydata,nticks=6):
00452         '''
00453         Input: rawxdata [run,fill,norbit,starttime,stoptime,totalls,ncmsls]
00454                rawydata {label:[instlumi]}
00455         '''
00456         runnum=rawxdata[0]
00457         fill=rawxdata[1]
00458         norbit=rawxdata[2]
00459         starttime=rawxdata[3]
00460         stoptime=rawxdata[4]
00461         totalls=rawxdata[-2]
00462         ncmsls=rawxdata[-1]
00463         peakinst=max(rawydata['Delivered'])
00464         lslength=float(norbit)*3564*25.0e-9
00465         totaldelivered=sum(rawydata['Delivered'])*lslength
00466         totalrecorded=sum(rawydata['Recorded'])*lslength
00467         xpoints=range(1,totalls+1)        
00468         #print len(xpoints)
00469         ypoints={}
00470         ymax={}
00471         for ylabel,yvalue in rawydata.items():
00472             ypoints[ylabel]=yvalue
00473             ymax[ylabel]=max(yvalue)
00474         left=0.15
00475         width=0.7
00476         bottom=0.1
00477         height=0.65
00478         bottom_h=bottom+height
00479         rect_scatter=[left,bottom,width,height]
00480         rect_table=[left,bottom_h,width,0.25]
00481         
00482         nullfmt=matplotlib.ticker.NullFormatter()
00483         nullloc=matplotlib.ticker.NullLocator()
00484         axtab=self.__fig.add_axes(rect_table,frameon=False)
00485         axtab.set_axis_off()
00486         axtab.xaxis.set_major_formatter(nullfmt)
00487         axtab.yaxis.set_major_formatter(nullfmt)
00488         axtab.xaxis.set_major_locator(nullloc)
00489         axtab.yaxis.set_major_locator(nullloc)
00490 
00491         ax=self.__fig.add_axes(rect_scatter)
00492         
00493         majorLoc=matplotlib.ticker.LinearLocator(numticks=nticks)
00494         minorLoc=matplotlib.ticker.LinearLocator(numticks=nticks*4)
00495         ax.set_xlabel(r'LS',position=(0.96,0))
00496         ax.set_ylabel(r'L $\mu$b$^{-1}$s$^{-1}$',position=(0,0.9))
00497         ax.xaxis.set_major_locator(majorLoc)
00498         ax.xaxis.set_minor_locator(minorLoc)
00499         ax.set_xbound(lower=xpoints[0],upper=xpoints[-1])
00500         xticklabels=ax.get_xticklabels()
00501         for tx in xticklabels:
00502             tx.set_horizontalalignment('right')
00503         ax.grid(True)
00504         keylist=ypoints.keys()
00505         keylist.sort()
00506         legendlist=[]
00507 
00508         for ylabel in keylist:
00509             cl='k'
00510             if self.colormap.has_key(ylabel):
00511                 cl=self.colormap[ylabel]
00512             ax.plot(xpoints,ypoints[ylabel],'.',label=ylabel,color=cl)
00513             legendlist.append(ylabel)      
00514         #ax.axhline(0,color='green',linewidth=0.2)
00515         ax.axvline(xpoints[ncmsls-1],color='green',linewidth=0.2)
00516 
00517         denomitor=1.0
00518         unitstring='/$\mu$b'
00519         if totaldelivered>=1.0e3 and totaldelivered<1.0e06:
00520             denomitor=1.0e3
00521             unitstring='/nb'
00522         elif totaldelivered>=1.0e6 and totaldelivered<1.0e9:
00523             denomitor=1.0e6
00524             unitstring='/pb'
00525         elif totaldelivered>=1.0e9 and totaldelivered<1.0e12:
00526             denomitor=1.0e9
00527             unitstring='/fb'
00528         elif totaldelivered>=1.0e12 and totaldelivered<1.0e15:
00529             denomitor=1.0e12
00530             unitstring='/ab'
00531         colLabels=('run','fill','max inst(/$\mu$b/s)','delivered('+unitstring+')','recorded('+unitstring+')')
00532         cellText=[[str(runnum),str(fill),'%.3f'%(peakinst),'%.3f'%(totaldelivered/denomitor),'%.3f'%(totalrecorded/denomitor)]]
00533        
00534         sumtable=axtab.table(cellText=cellText,colLabels=colLabels,colWidths=[0.12,0.1,0.27,0.27,0.27],cellLoc='center',loc='center')
00535         trans=matplotlib.transforms.BlendedGenericTransform(ax.transData,ax.transAxes)        
00536         axtab.add_table(sumtable)
00537         
00538         ax.text(xpoints[0],1.02,starttime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))   
00539         ax.text(xpoints[ncmsls-1],1.02,stoptime[0:17],transform=trans,horizontalalignment='left',size='x-small',color='green',bbox=dict(facecolor='white'))        
00540         ax.legend(tuple(legendlist),loc='upper right',numpoints=1)
00541 
00542     def drawHTTPstring(self):
00543         self.__canvas=CanvasBackend(self.__fig)    
00544         cherrypy.response.headers['Content-Type']='image/png'
00545         buf=StringIO()
00546         self.__canvas.print_png(buf)
00547         return buf.getvalue()
00548     
00549     def drawPNG(self,filename):
00550         self.__canvas=CanvasBackend(self.__fig)    
00551         self.__canvas.print_figure(filename)
00552     
00553     def drawInteractive(self):
00554         if batchonly:
00555             print 'interactive mode is not available for your setup, exit'
00556             sys.exit()    
00557         self.__canvas=CanvasBackend(self.__fig,master=root)
00558         self.__canvas.show()
00559         self.__canvas.get_tk_widget().pack(side=Tk.TOP,fill=Tk.BOTH,expand=1)
00560         toolbar=NavigationToolbar2TkAgg(self.__canvas,root)
00561         toolbar.update()
00562         self.__canvas._tkcanvas.pack(side=Tk.TOP,fill=Tk.BOTH,expand=1)
00563         button = Tk.Button(master=root,text='Quit',command=sys.exit)
00564         button.pack(side=Tk.BOTTOM)
00565         Tk.mainloop()
00566 if __name__=='__main__':
00567     fig=Figure(figsize=(5,5),dpi=100)
00568     a=fig.add_subplot(111)
00569     t=numpy.arange(0.0,3.0,0.01)
00570     s=numpy.sin(2*numpy.pi*t)
00571     a.plot(t,s)
00572     m=matplotRender(fig)
00573     m.drawPNG('testmatplotrender.png')
00574     m.drawInteractive()
00575     #print drawHTTPstring()