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