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 26 """ 27 28 GeneralPlotTimelines.__init__(self,timelines,custom,showWindow=showWindow,registry=registry) 29 Gnuplot.__init__(self,persist=self.spec.persist) 30 31 self.itemlist=[] 32 33 if self.spec.start or self.spec.end: 34 rng="[" 35 if self.spec.start: 36 rng+=str(self.spec.start) 37 rng+=":" 38 if self.spec.end: 39 rng+=str(self.spec.end) 40 rng+="]" 41 self.set_string("xrange "+rng) 42 43 if len(self.alternate)>0: 44 self.set_string("y2tics") 45 46 try: 47 if self.spec.logscale: 48 self.set_string("logscale y") 49 except AttributeError: 50 pass 51 52 try: 53 if self.spec.ylabel: 54 self.set_string('ylabel "'+self.spec.ylabel+'"') 55 except AttributeError: 56 pass 57 58 try: 59 if self.spec.xlabel: 60 self.set_string('xlabel "'+self.spec.xlabel+'"') 61 except AttributeError: 62 pass 63 64 try: 65 if self.spec.y2label: 66 self.set_string('y2label "'+self.spec.y2label+'"') 67 except AttributeError: 68 pass 69 70 raiseit=False 71 if "raiseit" in dir(self.spec): 72 raiseit=self.spec.raiseit 73 if raiseit: 74 x11addition=" raise" 75 else: 76 x11addition=" noraise" 77 78 if showWindow: 79 if uname()[0]=="Darwin": 80 self.set_string("terminal x11"+x11addition) 81 # self.set_string("terminal aqua "+str(GnuplotTimelines.terminalNr)) 82 GnuplotTimelines.terminalNr+=1 83 else: 84 self.set_string("terminal x11"+x11addition) 85 else: 86 self.set_string("terminal dumb") 87 88 self.with_=self.spec.with_ 89 90 self.redo()
91
92 - def buildData(self,times,name,title,lastValid):
93 """Build the implementation specific data 94 @param times: The vector of times for which data exists 95 @param name: the name under which the data is stored in the timeline 96 @param title: the title under which this will be displayed""" 97 98 tm=times 99 dt=self.data.getValues(name) 100 if len(tm)>0 and not lastValid: 101 tm=tm[:-1] 102 dt=dt[:-1] 103 104 if len(dt)>0: 105 it=Data(tm,dt,title=title,with_=self.with_) 106 107 if name in self.alternate: 108 it.set_option(axes="x1y2") 109 110 self.itemlist.append(it)
111
112 - def preparePlot(self):
113 """Prepare the plotting window""" 114 self.itemlist=[]
115
116 - def doReplot(self):
117 """Replot the whole data""" 118 119 self.replot()
120
121 - def actualSetTitle(self,title):
122 """Sets the title""" 123 124 self.title(title)
125
126 - def setYLabel(self,title):
127 """Sets the label on the first Y-Axis""" 128 129 self.set_string('ylabel "%s"' % title)
130
131 - def setYLabel2(self,title):
132 """Sets the label on the second Y-Axis""" 133 134 self.set_string('y2label "%s"' % title)
135
136 - def doHardcopy(self,filename,form):
137 """Write the contents of the plot to disk 138 @param filename: Name of the file without type extension 139 @param form: String describing the format""" 140 141 if form=="png": 142 self.hardcopy(terminal="png",filename=filename+".png",small=True) 143 elif form=="pdf": 144 self.hardcopy(terminal="pdf",filename=filename+".pdf",color=True) 145 elif form=="svg": 146 self.hardcopy(terminal="svg",filename=filename+".svg") 147 elif form=="postscript": 148 self.hardcopy(terminal="postscript",filename=filename+".ps",color=True) 149 elif form=="eps": 150 self.hardcopy(terminal="postscript",filename=filename+".eps",color=True,eps=True) 151 else: 152 warning("Hardcopy format",form,"unknown. Falling back to postscript") 153 self.hardcopy(filename=filename+".ps",color=True)
154 155 # Should work with Python3 and Python2 156