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

Source Code for Module PyFoam.Basics.GnuplotTimelines

  1  #  ICE Revision: $Id$ 
  2  """Plots a collection of timelines""" 
  3   
  4  from PyFoam.ThirdParty.Gnuplot import Gnuplot,Data 
  5   
  6  from PyFoam.Error import warning 
  7   
  8  from .GeneralPlotTimelines import GeneralPlotTimelines 
  9   
 10  from platform import uname 
 11   
12 -class GnuplotTimelines(GeneralPlotTimelines,Gnuplot):
13 """This class opens a gnuplot window and plots a timelines-collection in it""" 14 15 terminalNr=1 16
17 - def __init__(self, 18 timelines, 19 custom, 20 showWindow=True, 21 registry=None):
22 """@param timelines: The timelines object 23 @type timelines: TimeLineCollection 24 @param custom: A CustomplotInfo-object. Values in this object usually override the 25 other options. If the object has an attribute named gnuplotCommands 26 (which is assumed to be a string list) then these strings are executed during 27 initialization of the plot (the purpose of this is to set non-standard stuff) 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.xlabel: 62 self.set_string('xlabel "'+self.spec.xlabel+'"') 63 except AttributeError: 64 pass 65 66 try: 67 if self.spec.y2label: 68 self.set_string('y2label "'+self.spec.y2label+'"') 69 except AttributeError: 70 pass 71 72 raiseit=False 73 if "raiseit" in dir(self.spec): 74 raiseit=self.spec.raiseit 75 if raiseit: 76 x11addition=" raise" 77 else: 78 x11addition=" noraise" 79 80 if showWindow: 81 if uname()[0]=="Darwin": 82 self.set_string("terminal x11"+x11addition) 83 # self.set_string("terminal aqua "+str(GnuplotTimelines.terminalNr)) 84 GnuplotTimelines.terminalNr+=1 85 else: 86 self.set_string("terminal x11"+x11addition) 87 else: 88 self.set_string("terminal dumb") 89 90 self.with_=self.spec.with_ 91 92 try: 93 for l in custom.gnuplotCommands: 94 self(l) 95 except AttributeError: 96 pass 97 98 self.redo()
99
100 - def buildData(self,times,name,title,lastValid):
101 """Build the implementation specific data 102 @param times: The vector of times for which data exists 103 @param name: the name under which the data is stored in the timeline 104 @param title: the title under which this will be displayed""" 105 106 tm=times 107 dt=self.data.getValues(name) 108 if len(tm)>0 and not lastValid: 109 tm=tm[:-1] 110 dt=dt[:-1] 111 112 if len(dt)>0: 113 it=Data(tm,dt,title=title,with_=self.with_) 114 115 if self.testAlternate(name): 116 it.set_option(axes="x1y2") 117 118 self.itemlist.append(it)
119
120 - def preparePlot(self):
121 """Prepare the plotting window""" 122 self.itemlist=[]
123
124 - def doReplot(self):
125 """Replot the whole data""" 126 127 self.replot()
128
129 - def actualSetTitle(self,title):
130 """Sets the title""" 131 132 self.title(title)
133
134 - def setYLabel(self,title):
135 """Sets the label on the first Y-Axis""" 136 137 self.set_string('ylabel "%s"' % title)
138
139 - def setYLabel2(self,title):
140 """Sets the label on the second Y-Axis""" 141 142 self.set_string('y2label "%s"' % title)
143
144 - def doHardcopy(self,filename,form):
145 """Write the contents of the plot to disk 146 @param filename: Name of the file without type extension 147 @param form: String describing the format""" 148 149 if form=="png": 150 self.hardcopy(terminal="png",filename=filename+".png",small=True) 151 elif form=="pdf": 152 self.hardcopy(terminal="pdf",filename=filename+".pdf",color=True) 153 elif form=="svg": 154 self.hardcopy(terminal="svg",filename=filename+".svg") 155 elif form=="postscript": 156 self.hardcopy(terminal="postscript",filename=filename+".ps",color=True) 157 elif form=="eps": 158 self.hardcopy(terminal="postscript",filename=filename+".eps",color=True,eps=True) 159 else: 160 warning("Hardcopy format",form,"unknown. Falling back to postscript") 161 self.hardcopy(filename=filename+".ps",color=True)
162 163 # Should work with Python3 and Python2 164