Package PyFoam :: Package Basics :: Module GnuplotTimelines
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.GnuplotTimelines

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Basics/GnuplotTimelines.py 6539 2010-05-04T19:25:43.455866Z bgschaid  $  
  2  """Plots a collection of timelines""" 
  3   
  4  from PyFoam.ThirdParty.Gnuplot import Gnuplot,Data 
  5       
  6  from PyFoam.Basics.CustomPlotInfo import readCustomPlotInfo,CustomPlotInfo 
  7   
  8  from PyFoam.Error import warning 
  9   
 10  from GeneralPlotTimelines import GeneralPlotTimelines 
 11   
 12  from os import uname 
 13   
14 -class GnuplotTimelines(GeneralPlotTimelines,Gnuplot):
15 """This class opens a gnuplot window and plots a timelines-collection in it""" 16 17 terminalNr=1 18
19 - def __init__(self, 20 timelines, 21 custom, 22 showWindow=True, 23 registry=None):
24 """@param timelines: The timelines object 25 @type timelines: TimeLineCollection 26 @param custom: A CustomplotInfo-object. Values in this object usually override the 27 other options 28 """ 29 30 GeneralPlotTimelines.__init__(self,timelines,custom,showWindow=showWindow,registry=registry) 31 Gnuplot.__init__(self,persist=self.spec.persist) 32 33 self.itemlist=[] 34 35 if self.spec.start or self.spec.end: 36 rng="[" 37 if self.spec.start: 38 rng+=str(self.spec.start) 39 rng+=":" 40 if self.spec.end: 41 rng+=str(self.spec.end) 42 rng+="]" 43 self.set_string("xrange "+rng) 44 45 if len(self.alternate)>0: 46 self.set_string("y2tics") 47 48 try: 49 if self.spec.logscale: 50 self.set_string("logscale y") 51 except AttributeError: 52 pass 53 54 try: 55 if self.spec.ylabel: 56 self.set_string('ylabel "'+self.spec.ylabel+'"') 57 except AttributeError: 58 pass 59 60 try: 61 if self.spec.y2label: 62 self.set_string('y2label "'+self.spec.y2label+'"') 63 except AttributeError: 64 pass 65 66 raiseit=False 67 if "raiseit" in dir(self.spec): 68 raiseit=self.spec.raiseit 69 if raiseit: 70 x11addition=" raise" 71 else: 72 x11addition=" noraise" 73 74 if showWindow: 75 if uname()[0]=="Darwin": 76 self.set_string("terminal x11"+x11addition) 77 # self.set_string("terminal aqua "+str(GnuplotTimelines.terminalNr)) 78 GnuplotTimelines.terminalNr+=1 79 else: 80 self.set_string("terminal x11"+x11addition) 81 else: 82 self.set_string("terminal dumb") 83 84 self.with_=self.spec.with_ 85 86 self.redo()
87
88 - def buildData(self,times,name,title,lastValid):
89 """Build the implementation specific data 90 @param times: The vector of times for which data exists 91 @param name: the name under which the data is stored in the timeline 92 @param title: the title under which this will be displayed""" 93 94 tm=times 95 dt=self.data.getValues(name) 96 if len(tm)>0 and not lastValid: 97 tm=tm[:-1] 98 dt=dt[:-1] 99 100 if len(dt)>0: 101 it=Data(tm,dt,title=title,with_=self.with_) 102 103 if name in self.alternate: 104 it.set_option(axes="x1y2") 105 106 self.itemlist.append(it)
107
108 - def preparePlot(self):
109 """Prepare the plotting window""" 110 self.itemlist=[]
111
112 - def doReplot(self):
113 """Replot the whole data""" 114 115 self.replot()
116
117 - def actualSetTitle(self,title):
118 """Sets the title""" 119 120 self.title(title)
121
122 - def setYLabel(self,title):
123 """Sets the label on the first Y-Axis""" 124 125 self.set_string('ylabel "%s"' % title)
126
127 - def setYLabel2(self,title):
128 """Sets the label on the second Y-Axis""" 129 130 self.set_string('y2label "%s"' % title)
131
132 - def doHardcopy(self,filename,form):
133 """Write the contents of the plot to disk 134 @param filename: Name of the file without type extension 135 @param form: String describing the format""" 136 137 if form=="png": 138 self.hardcopy(terminal="png",filename=filename+".png",color=True,small=True) 139 elif form=="pdf": 140 self.hardcopy(terminal="pdf",filename=filename+".pdf",color=True) 141 elif form=="svg": 142 self.hardcopy(terminal="svg",filename=filename+".svg") 143 elif form=="postscript": 144 self.hardcopy(terminal="postscript",filename=filename+".ps",color=True) 145 elif form=="eps": 146 self.hardcopy(terminal="postscript",filename=filename+".eps",color=True,eps=True) 147 else: 148 warning("Hardcopy format",form,"unknown. Falling back to postscript") 149 self.hardcopy(filename=filename+".ps",color=True)
150