1
2 """Plots a collection of timelines"""
3
4 from PyFoam.ThirdParty.Gnuplot import Gnuplot,Data
5
6 from os import uname
7
9 """This class opens a gnuplot window and plots a timelines-collection in it"""
10
11 terminalNr=1
12
13 - def __init__(self,timelines,persist=None,raiseit=True,with="lines",alternateAxis=[],forbidden=[],start=None,end=None,logscale=False):
14 """@param timelines: The timelines object
15 @type timelines: TimeLineCollection
16 @param persist: Gnuplot window persistst after run
17 @param raiseit: Raise the window at every plot
18 @param with: how to plot the data (lines, points, steps)
19 @param alternateAxis: list with names that ought to appear on the alternate y-axis
20 @param forbidden: A list with strings. If one of those strings is found in a name, it is not plotted
21 @param start: First time that should be plotted. If undefined everything from the start is plotted
22 @param end: Last time that should be plotted. If undefined data is plotted indefinitly
23 @param logscale: Scale the y-axis logarithmic
24 """
25
26 Gnuplot.__init__(self,persist=persist)
27 self.alternate=alternateAxis
28 self.forbidden=forbidden
29
30 if start or end:
31 rng="["
32 if start:
33 rng+=str(start)
34 rng+=":"
35 if end:
36 rng+=str(end)
37 rng+="]"
38 self.set_string("xrange "+rng)
39
40 if len(self.alternate)>0:
41 self.set_string("y2tics")
42
43 if logscale:
44 self.set_string("logscale y")
45
46 if raiseit:
47 x11addition=" raise"
48 else:
49 x11addition=" noraise"
50
51 if uname()[0]=="Darwin":
52 self.set_string("terminal x11"+x11addition)
53
54 GnuplotTimelines.terminalNr+=1
55 else:
56 self.set_string("terminal x11"+x11addition)
57
58 self.data=timelines
59 self.with=with
60
61 self.redo()
62
64 """Replot the timelines"""
65 times=self.data.getTimes()
66 if len(times)<=0:
67 return
68
69 tmp=self.data.getValueNames()
70 names=[]
71 for n in tmp:
72 addIt=True
73 for f in self.forbidden:
74 if n.find(f)>=0:
75 addIt=False
76 break
77 if addIt:
78 names.append(n)
79
80 self.itemlist=[]
81 for n in names:
82 it=Data(times,self.data.getValues(n),title=n,with=self.with)
83 if n in self.alternate:
84 it.set_option(axes="x1y2")
85
86 self.itemlist.append(it)
87
88 if len(names)>0 and len(times)>0:
89 self.replot()
90