3 from ..
import Exceptions
4 from ..
import PlotTools
5 from ..
import Utilities
12 Graphical User Interface for plotting data.
14 @var _plotDashedIfNegative Whether the negative parts of plots should instead be plotted
15 positively, but with dashed lines.
16 @var _yScaleIsLog Whether the y axis is logarithmic.
17 @var _plotSelector Instance of _PlotSelectionList used to select plots for display.
18 @var _hiddenCharacteristics List of plot characteristics that are hidden in the plot selector.
19 @var _characteristicsOrder Order of the plot characteristics.
34 def provideData(self, x, y, show=True, label=None, characteristics=None):
36 Provides a new plot by specifying the x and y coordinates.
38 @param[in] x A list of x coordinates.
39 @param[in] y A list of y coordinates corresponding to the x coordinates.
40 @param[in] show Whether to draw the plot initially, as a bool.
41 @param[in] label The label for the plot.
42 @param[in] characteristics Plot characteristics, as used in the plot selection window.
43 @throw TypeError Throws if show is not of type bool.
46 if type(show)
is not bool:
47 raise TypeError(
"Inavlid type for parameter 'show'")
51 lines = self.
plot(x, y, label=label)
52 self.
app.canvasFrame.update()
54 if characteristics
is None:
57 self.
plots[self.
nextPlotID] = {
'lines': lines,
'x': x,
'y': y,
'show': show,
'label': label,
'characteristics': characteristics}
64 Adds the given file, or rather its contents, to the list of available plots.
66 The added plot is not drawn on the canvas.
68 Each line in the file that is of the form
70 is considered to describe the plot's characteristic "name", the value of which
71 is "value". "value" is treated as a float, if possible, and as a string otherwise.
73 Any other line must consist of a float, followed by a space, and another float.
74 The first float corresponds to the x coordinate of a plot point, the second
75 float is the corresponding y coordinate.
77 @param[in] path The path to the file.
78 @param[in] characteristics A dictionary of characteristics for the plot.
79 Conflicting file comments are ignored.
80 @throw FileFormatException Throws if the given file did not adhere to the expected format.
86 with Utilities.openPossiblyCompressedFile(path)
as file:
89 parts = line.split(
'=')
90 if len(parts) > 0
and parts[0][1:].strip() ==
'rundirs':
91 parts = line.split(
'=', 1)
96 property_, value = parts
97 property_ = property_[1:].strip()
99 if property_
in characteristics:
106 characteristics[property_] = value
114 x.append(float(parts[0]))
115 y.append(float(parts[1]))
117 self.
provideData(x, y, show=
False, characteristics=characteristics)
121 Adds all files in the given directory to the available data files.
123 Each file corresponds to a plot.
124 The added plots are not drawn on the canvas.
126 @param[in] path The path to the directory to be added.
127 @param[in] characteristics A dictionary of characteristics for all plots.
128 Conflicting file comments are ignored.
129 @param[in] recursive Whether to traverse the directory recursively.
130 @throw FileFormatException Any of the given files did not adhere to the expected format,
131 as described in provideDataFile.
134 for file
in os.listdir(path):
135 filepath = path +
'/' + file
136 if os.path.isfile(filepath):
142 def setXScale(self, scale):
143 self.
app.canvasFrame.axes.set_xscale(scale)
144 self.
app.canvasFrame.setLogXCheckbox(scale ==
'log')
146 def setYScale(self, scale):
147 self.
app.canvasFrame.axes.set_yscale(scale)
148 self.
app.canvasFrame.setLogYCheckbox(scale ==
'log')
154 def setPlotDashedIfNegative(self, state):
156 self.
app.canvasFrame.setDashedIfNegativeCheckbox(state)
161 Hides the given characteristics from the plot selection window.
163 @param[in] toHide A list of plot characteristics to hide.
171 Sets the order in which plot characteristics are displayed in the plot selection window.
173 @param[in] order An ordered list of characteristics to display. Characteristics not in
174 this list will be displayed in undetermined order after all
175 characteristics present in this list.
182 Sets by which characteristic to sort the plots in the plot selection window.
184 @param[in] characteristic The characteristic name to sort by.
185 @param[in] ascending Set to true to sort by ascending values, false for descending.
186 @throw InvalidArgumentException Throws if there is no such characteristic.
193 if name == characteristic:
202 def toggleVisibility(self, plotID):
203 if not self.
plots[plotID][
'show']:
204 lines = self.
plot(self.
plots[plotID][
'x'], self.
plots[plotID][
'y'], label=self.
plots[plotID][
'label'])
205 self.
plots[plotID][
'lines'] = lines
206 self.
plots[plotID][
'show'] =
True
208 for line
in self.
plots[plotID][
'lines']:
209 self.
app.canvasFrame.axes.lines.remove(line)
210 self.
plots[plotID][
'lines'] =
None
211 self.
plots[plotID][
'show'] =
False
213 self.
app.canvasFrame.update()
217 for line
in self.
app.canvasFrame.axes.get_lines():
218 self.
app.canvasFrame.axes.lines.remove(line)
220 self.
app.canvasFrame.axes.set_color_cycle(
None)
221 for plotID, plot
in self.
plots.items():
224 lines = self.
plot(plot[
'x'], plot[
'y'], label=plot[
'label'])
226 plot[
'lines'] = lines
228 def plot(self, x, y, **kwargs):
230 lines = PlotTools.plotDashedIfNegative(x, y, logY=self.
_yScaleIsLog, ax=self.
app.canvasFrame.axes, **kwargs)
232 lines = self.
app.canvasFrame.axes.plot(x, y, **kwargs)
236 def _updatePlotSelector(self):
238 Updates the plot selector.
252 columnWidths[name] = self.
_plotSelector.GetColumnWidth(column)
257 for characteristic
in characteristics:
262 if characteristic
in columnWidths:
263 self.
_plotSelector.SetColumnWidth(column, columnWidths[characteristic])
269 for plotID, plot
in self.
plots.items():
270 plotCharacteristics = []
272 for characteristic
in characteristics:
276 if characteristic ==
'Plotted':
277 plotCharacteristics.append(plot[
'show'])
280 if characteristic
in plot[
'characteristics']:
281 plotCharacteristics.append(plot[
'characteristics'][characteristic])
283 plotCharacteristics.append(
None)
285 plotDict[plotID] = plotCharacteristics
291 if sortState
is not None:
295 def _getListOfPlotCharacteristics(self, initial=[]):
297 Returns a list of characteristics that are used in any of the known plots.
299 @param[in] initial A list of characteristics that are to be included in the returned result,
300 even if not used by any plot.
306 if c
in characteristics:
310 characteristics.append(c)
313 for _plotID, plot
in self.
plots.items():
314 if c
in plot[
'characteristics'].keys():
315 characteristics.append(c)
320 if c
not in characteristics:
321 characteristics.append(c)
323 for _plotID, plot
in self.
plots.items():
324 for c
in plot[
'characteristics'].keys():
325 if c
not in characteristics:
326 characteristics.append(c)
328 return characteristics
330 def _registerPlotSelector(self, plotSelector):
332 Registers an instance of _PlotSelectionList
334 @param[in] plotSelector The instance to register.