[8cb6cd6] | 1 | from PyQt4 import QtGui |
---|
[aadf0af1] | 2 | from PyQt4 import QtCore |
---|
| 3 | import functools |
---|
| 4 | import copy |
---|
[8cb6cd6] | 5 | |
---|
| 6 | import matplotlib.pyplot as plt |
---|
[9290b1a] | 7 | from matplotlib.font_manager import FontProperties |
---|
[8cb6cd6] | 8 | |
---|
[9290b1a] | 9 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
[ef01be4] | 10 | from sas.qtgui.PlotterBase import PlotterBase |
---|
[aadf0af1] | 11 | import sas.qtgui.GuiUtils as GuiUtils |
---|
[9290b1a] | 12 | from sas.qtgui.AddText import AddText |
---|
[d3ca363] | 13 | from sas.qtgui.SetGraphRange import SetGraphRange |
---|
[570a58f9] | 14 | from sas.qtgui.LinearFit import LinearFit |
---|
[8cb6cd6] | 15 | |
---|
[416fa8f] | 16 | class PlotterWidget(PlotterBase): |
---|
[c4e5400] | 17 | """ |
---|
| 18 | 1D Plot widget for use with a QDialog |
---|
[fecfe28] | 19 | """ |
---|
[416fa8f] | 20 | def __init__(self, parent=None, manager=None, quickplot=False): |
---|
| 21 | super(PlotterWidget, self).__init__(parent, manager=manager, quickplot=quickplot) |
---|
[570a58f9] | 22 | |
---|
[27313b7] | 23 | self.parent = parent |
---|
[8cb6cd6] | 24 | |
---|
[aadf0af1] | 25 | # Dictionary of {plot_id:Data1d} |
---|
| 26 | self.plot_dict = {} |
---|
| 27 | |
---|
| 28 | # Simple window for data display |
---|
| 29 | self.txt_widget = QtGui.QTextEdit(None) |
---|
[fed94a2] | 30 | # Window for text add |
---|
| 31 | self.addText = AddText(self) |
---|
[aadf0af1] | 32 | |
---|
[fed94a2] | 33 | # Log-ness of the axes |
---|
[570a58f9] | 34 | self.xLogLabel = "log10(x)" |
---|
| 35 | self.yLogLabel = "log10(y)" |
---|
| 36 | |
---|
| 37 | # Data container for the linear fit |
---|
[fed94a2] | 38 | self.fit_result = Data1D(x=[], y=[], dy=None) |
---|
| 39 | self.fit_result.symbol = 13 |
---|
| 40 | self.fit_result.name = "Fit" |
---|
[570a58f9] | 41 | |
---|
| 42 | # Add a slot for receiving update signal from LinearFit |
---|
[fed94a2] | 43 | # NEW style signals |
---|
[570a58f9] | 44 | #self.updatePlot = QtCore.pyqtSignal(tuple) |
---|
[fed94a2] | 45 | # self.updatePlot.connect(self.onFitDisplay) |
---|
| 46 | # OLD style signals |
---|
[570a58f9] | 47 | QtCore.QObject.connect(self, QtCore.SIGNAL('updatePlot'), self.onFitDisplay) |
---|
| 48 | |
---|
[31c5b58] | 49 | @property |
---|
| 50 | def data(self): |
---|
| 51 | return self._data |
---|
| 52 | |
---|
| 53 | @data.setter |
---|
| 54 | def data(self, value): |
---|
[8cb6cd6] | 55 | """ data setter """ |
---|
[31c5b58] | 56 | self._data = value |
---|
[6d05e1d] | 57 | self.xLabel = "%s(%s)"%(value._xaxis, value._xunit) |
---|
| 58 | self.yLabel = "%s(%s)"%(value._yaxis, value._yunit) |
---|
[aadf0af1] | 59 | self.title(title=value.name) |
---|
[8cb6cd6] | 60 | |
---|
[9290b1a] | 61 | def plot(self, data=None, marker=None, linestyle=None, hide_error=False): |
---|
[8cb6cd6] | 62 | """ |
---|
[aadf0af1] | 63 | Add a new plot of self._data to the chart. |
---|
[8cb6cd6] | 64 | """ |
---|
[9290b1a] | 65 | # Data1D |
---|
| 66 | if isinstance(data, Data1D): |
---|
| 67 | self.data = data |
---|
| 68 | assert(self._data) |
---|
| 69 | |
---|
[570a58f9] | 70 | is_fit = (self._data.id=="fit") |
---|
| 71 | |
---|
[fed94a2] | 72 | # Shortcut for the current axis |
---|
[ef01be4] | 73 | ax = self.ax |
---|
[8cb6cd6] | 74 | |
---|
[39551a68] | 75 | if marker == None: |
---|
[6d05e1d] | 76 | marker = 'o' |
---|
[39551a68] | 77 | |
---|
| 78 | if linestyle == None: |
---|
[b4b8589] | 79 | linestyle = '' |
---|
| 80 | |
---|
[aadf0af1] | 81 | if not self._title: |
---|
| 82 | self.title(title=self.data.name) |
---|
| 83 | |
---|
[b4b8589] | 84 | # plot data with/without errorbars |
---|
[c4e5400] | 85 | if hide_error: |
---|
[aadf0af1] | 86 | line = ax.plot(self._data.view.x, self._data.view.y, |
---|
[c4e5400] | 87 | marker=marker, |
---|
| 88 | linestyle=linestyle, |
---|
[9290b1a] | 89 | label=self._title, |
---|
| 90 | picker=True) |
---|
[c4e5400] | 91 | else: |
---|
[aadf0af1] | 92 | line = ax.errorbar(self._data.view.x, self._data.view.y, |
---|
| 93 | yerr=self._data.view.dy, xerr=None, |
---|
[c4e5400] | 94 | capsize=2, linestyle='', |
---|
| 95 | barsabove=False, |
---|
| 96 | marker=marker, |
---|
| 97 | lolims=False, uplims=False, |
---|
| 98 | xlolims=False, xuplims=False, |
---|
[9290b1a] | 99 | label=self._title, |
---|
| 100 | picker=True) |
---|
[8cb6cd6] | 101 | |
---|
[aadf0af1] | 102 | # Update the list of data sets (plots) in chart |
---|
| 103 | self.plot_dict[self._data.id] = self.data |
---|
| 104 | |
---|
[8cb6cd6] | 105 | # Now add the legend with some customizations. |
---|
[9290b1a] | 106 | self.legend = ax.legend(loc='upper right', shadow=True) |
---|
| 107 | self.legend.set_picker(True) |
---|
[8cb6cd6] | 108 | |
---|
[6d05e1d] | 109 | # Current labels for axes |
---|
[570a58f9] | 110 | if self.y_label and not is_fit: |
---|
| 111 | ax.set_ylabel(self.y_label) |
---|
| 112 | if self.x_label and not is_fit: |
---|
| 113 | ax.set_xlabel(self.x_label) |
---|
[6d05e1d] | 114 | |
---|
[ef01be4] | 115 | # Title only for regular charts |
---|
[570a58f9] | 116 | if not self.quickplot and not is_fit: |
---|
[6d05e1d] | 117 | ax.set_title(label=self._title) |
---|
[8cb6cd6] | 118 | |
---|
[6d05e1d] | 119 | # Include scaling (log vs. linear) |
---|
| 120 | ax.set_xscale(self.xscale) |
---|
[3b7b218] | 121 | ax.set_yscale(self.yscale) |
---|
[8cb6cd6] | 122 | |
---|
[257bd57] | 123 | # define the ranges |
---|
| 124 | self.setRange = SetGraphRange(parent=self, |
---|
| 125 | x_range=self.ax.get_xlim(), y_range=self.ax.get_ylim()) |
---|
| 126 | |
---|
[8cb6cd6] | 127 | # refresh canvas |
---|
| 128 | self.canvas.draw() |
---|
| 129 | |
---|
[aadf0af1] | 130 | def createContextMenu(self): |
---|
[c4e5400] | 131 | """ |
---|
| 132 | Define common context menu and associated actions for the MPL widget |
---|
| 133 | """ |
---|
| 134 | self.defaultContextMenu() |
---|
| 135 | |
---|
[aadf0af1] | 136 | # Separate plots |
---|
| 137 | self.addPlotsToContextMenu() |
---|
| 138 | |
---|
[27313b7] | 139 | # Additional menu items |
---|
| 140 | self.contextMenu.addSeparator() |
---|
| 141 | self.actionModifyGraphAppearance =\ |
---|
| 142 | self.contextMenu.addAction("Modify Graph Appearance") |
---|
| 143 | self.contextMenu.addSeparator() |
---|
| 144 | self.actionAddText = self.contextMenu.addAction("Add Text") |
---|
| 145 | self.actionRemoveText = self.contextMenu.addAction("Remove Text") |
---|
| 146 | self.contextMenu.addSeparator() |
---|
| 147 | self.actionChangeScale = self.contextMenu.addAction("Change Scale") |
---|
| 148 | self.contextMenu.addSeparator() |
---|
| 149 | self.actionSetGraphRange = self.contextMenu.addAction("Set Graph Range") |
---|
| 150 | self.actionResetGraphRange =\ |
---|
| 151 | self.contextMenu.addAction("Reset Graph Range") |
---|
| 152 | # Add the title change for dialogs |
---|
[aadf0af1] | 153 | #if self.parent: |
---|
| 154 | self.contextMenu.addSeparator() |
---|
| 155 | self.actionWindowTitle = self.contextMenu.addAction("Window Title") |
---|
[27313b7] | 156 | |
---|
| 157 | # Define the callbacks |
---|
| 158 | self.actionModifyGraphAppearance.triggered.connect(self.onModifyGraph) |
---|
| 159 | self.actionAddText.triggered.connect(self.onAddText) |
---|
| 160 | self.actionRemoveText.triggered.connect(self.onRemoveText) |
---|
| 161 | self.actionChangeScale.triggered.connect(self.onScaleChange) |
---|
| 162 | self.actionSetGraphRange.triggered.connect(self.onSetGraphRange) |
---|
| 163 | self.actionResetGraphRange.triggered.connect(self.onResetGraphRange) |
---|
| 164 | self.actionWindowTitle.triggered.connect(self.onWindowsTitle) |
---|
[c4e5400] | 165 | |
---|
[aadf0af1] | 166 | def addPlotsToContextMenu(self): |
---|
| 167 | """ |
---|
| 168 | Adds operations on all plotted sets of data to the context menu |
---|
| 169 | """ |
---|
| 170 | for id in self.plot_dict.keys(): |
---|
| 171 | plot = self.plot_dict[id] |
---|
| 172 | name = plot.name |
---|
| 173 | plot_menu = self.contextMenu.addMenu('&%s' % name) |
---|
| 174 | |
---|
| 175 | self.actionDataInfo = plot_menu.addAction("&DataInfo") |
---|
| 176 | self.actionDataInfo.triggered.connect( |
---|
| 177 | functools.partial(self.onDataInfo, plot)) |
---|
| 178 | |
---|
| 179 | self.actionSavePointsAsFile = plot_menu.addAction("&Save Points as a File") |
---|
| 180 | self.actionSavePointsAsFile.triggered.connect( |
---|
| 181 | functools.partial(self.onSavePoints, plot)) |
---|
| 182 | plot_menu.addSeparator() |
---|
| 183 | |
---|
| 184 | if plot.id != 'fit': |
---|
| 185 | self.actionLinearFit = plot_menu.addAction('&Linear Fit') |
---|
[570a58f9] | 186 | self.actionLinearFit.triggered.connect( |
---|
| 187 | functools.partial(self.onLinearFit, id)) |
---|
[aadf0af1] | 188 | plot_menu.addSeparator() |
---|
| 189 | |
---|
| 190 | self.actionRemovePlot = plot_menu.addAction("Remove") |
---|
| 191 | self.actionRemovePlot.triggered.connect( |
---|
| 192 | functools.partial(self.onRemovePlot, id)) |
---|
| 193 | |
---|
| 194 | if not plot.is_data: |
---|
| 195 | self.actionFreeze = plot_menu.addAction('&Freeze') |
---|
| 196 | self.actionFreeze.triggered.connect( |
---|
| 197 | functools.partial(self.onFreeze, id)) |
---|
| 198 | plot_menu.addSeparator() |
---|
| 199 | |
---|
| 200 | if plot.is_data: |
---|
| 201 | self.actionHideError = plot_menu.addAction("Hide Error Bar") |
---|
| 202 | if plot.dy is not None and plot.dy != []: |
---|
| 203 | if plot.hide_error: |
---|
| 204 | self.actionHideError.setText('Show Error Bar') |
---|
| 205 | else: |
---|
| 206 | self.actionHideError.setEnabled(False) |
---|
| 207 | self.actionHideError.triggered.connect( |
---|
| 208 | functools.partial(self.onToggleHideError, id)) |
---|
| 209 | plot_menu.addSeparator() |
---|
| 210 | |
---|
| 211 | self.actionModifyPlot = plot_menu.addAction('&Modify Plot Property') |
---|
| 212 | self.actionModifyPlot.triggered.connect(self.onModifyPlot) |
---|
| 213 | |
---|
| 214 | def createContextMenuQuick(self): |
---|
[6d05e1d] | 215 | """ |
---|
| 216 | Define context menu and associated actions for the quickplot MPL widget |
---|
| 217 | """ |
---|
[c4e5400] | 218 | # Default actions |
---|
| 219 | self.defaultContextMenu() |
---|
| 220 | |
---|
| 221 | # Additional actions |
---|
[6d05e1d] | 222 | self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off") |
---|
| 223 | self.contextMenu.addSeparator() |
---|
| 224 | self.actionChangeScale = self.contextMenu.addAction("Change Scale") |
---|
| 225 | |
---|
| 226 | # Define the callbacks |
---|
| 227 | self.actionToggleGrid.triggered.connect(self.onGridToggle) |
---|
| 228 | self.actionChangeScale.triggered.connect(self.onScaleChange) |
---|
| 229 | |
---|
| 230 | def onScaleChange(self): |
---|
| 231 | """ |
---|
| 232 | Show a dialog allowing axes rescaling |
---|
| 233 | """ |
---|
| 234 | if self.properties.exec_() == QtGui.QDialog.Accepted: |
---|
[570a58f9] | 235 | self.xLogLabel, self.yLogLabel = self.properties.getValues() |
---|
| 236 | self.xyTransform(self.xLogLabel, self.yLogLabel) |
---|
[6d05e1d] | 237 | |
---|
[27313b7] | 238 | def onModifyGraph(self): |
---|
| 239 | """ |
---|
| 240 | Show a dialog allowing chart manipulations |
---|
| 241 | """ |
---|
| 242 | print ("onModifyGraph") |
---|
| 243 | pass |
---|
| 244 | |
---|
| 245 | def onAddText(self): |
---|
| 246 | """ |
---|
| 247 | Show a dialog allowing adding custom text to the chart |
---|
| 248 | """ |
---|
[9290b1a] | 249 | if self.addText.exec_() == QtGui.QDialog.Accepted: |
---|
| 250 | # Retrieve the new text, its font and color |
---|
| 251 | extra_text = self.addText.text() |
---|
| 252 | extra_font = self.addText.font() |
---|
| 253 | extra_color = self.addText.color() |
---|
| 254 | |
---|
| 255 | # Place the text on the screen at (0,0) |
---|
| 256 | pos_x = self.x_click |
---|
| 257 | pos_y = self.y_click |
---|
| 258 | |
---|
| 259 | # Map QFont onto MPL font |
---|
| 260 | mpl_font = FontProperties() |
---|
| 261 | mpl_font.set_size(int(extra_font.pointSize())) |
---|
| 262 | mpl_font.set_family(str(extra_font.family())) |
---|
| 263 | mpl_font.set_weight(int(extra_font.weight())) |
---|
| 264 | # MPL style names |
---|
| 265 | styles = ['normal', 'italic', 'oblique'] |
---|
| 266 | # QFont::Style maps directly onto the above |
---|
| 267 | try: |
---|
| 268 | mpl_font.set_style(styles[extra_font.style()]) |
---|
| 269 | except: |
---|
| 270 | pass |
---|
| 271 | |
---|
| 272 | if len(extra_text) > 0: |
---|
| 273 | new_text = self.ax.text(str(pos_x), |
---|
| 274 | str(pos_y), |
---|
| 275 | extra_text, |
---|
| 276 | color=extra_color, |
---|
| 277 | fontproperties=mpl_font) |
---|
| 278 | # Update the list of annotations |
---|
| 279 | self.textList.append(new_text) |
---|
| 280 | self.canvas.draw_idle() |
---|
[27313b7] | 281 | |
---|
| 282 | def onRemoveText(self): |
---|
| 283 | """ |
---|
[9290b1a] | 284 | Remove the most recently added text |
---|
[27313b7] | 285 | """ |
---|
[d3ca363] | 286 | num_text = len(self.textList) |
---|
| 287 | if num_text < 1: |
---|
| 288 | return |
---|
| 289 | txt = self.textList[num_text - 1] |
---|
| 290 | text_remove = txt.get_text() |
---|
| 291 | txt.remove() |
---|
| 292 | self.textList.remove(txt) |
---|
| 293 | |
---|
| 294 | self.canvas.draw_idle() |
---|
[27313b7] | 295 | |
---|
| 296 | def onSetGraphRange(self): |
---|
| 297 | """ |
---|
| 298 | Show a dialog allowing setting the chart ranges |
---|
| 299 | """ |
---|
[d3ca363] | 300 | # min and max of data |
---|
| 301 | if self.setRange.exec_() == QtGui.QDialog.Accepted: |
---|
[257bd57] | 302 | x_range = self.setRange.xrange() |
---|
| 303 | y_range = self.setRange.yrange() |
---|
| 304 | if x_range is not None and y_range is not None: |
---|
| 305 | self.ax.set_xlim(x_range) |
---|
| 306 | self.ax.set_ylim(y_range) |
---|
| 307 | self.canvas.draw_idle() |
---|
[27313b7] | 308 | |
---|
| 309 | def onResetGraphRange(self): |
---|
| 310 | """ |
---|
[d3ca363] | 311 | Resets the chart X and Y ranges to their original values |
---|
[27313b7] | 312 | """ |
---|
[d3ca363] | 313 | x_range = (self.data.x.min(), self.data.x.max()) |
---|
| 314 | y_range = (self.data.y.min(), self.data.y.max()) |
---|
[257bd57] | 315 | if x_range is not None and y_range is not None: |
---|
| 316 | self.ax.set_xlim(x_range) |
---|
| 317 | self.ax.set_ylim(y_range) |
---|
| 318 | self.canvas.draw_idle() |
---|
[27313b7] | 319 | |
---|
[aadf0af1] | 320 | def onDataInfo(self, plot_data): |
---|
| 321 | """ |
---|
| 322 | Displays data info text window for the selected plot |
---|
| 323 | """ |
---|
| 324 | text_to_show = GuiUtils.retrieveData1d(plot_data) |
---|
| 325 | # Hardcoded sizes to enable full width rendering with default font |
---|
| 326 | self.txt_widget.resize(420,600) |
---|
| 327 | |
---|
| 328 | self.txt_widget.setReadOnly(True) |
---|
| 329 | self.txt_widget.setWindowFlags(QtCore.Qt.Window) |
---|
| 330 | self.txt_widget.setWindowIcon(QtGui.QIcon(":/res/ball.ico")) |
---|
| 331 | self.txt_widget.setWindowTitle("Data Info: %s" % plot_data.filename) |
---|
| 332 | self.txt_widget.insertPlainText(text_to_show) |
---|
| 333 | |
---|
| 334 | self.txt_widget.show() |
---|
| 335 | # Move the slider all the way up, if present |
---|
| 336 | vertical_scroll_bar = self.txt_widget.verticalScrollBar() |
---|
| 337 | vertical_scroll_bar.triggerAction(QtGui.QScrollBar.SliderToMinimum) |
---|
| 338 | |
---|
| 339 | def onSavePoints(self, plot_data): |
---|
| 340 | """ |
---|
| 341 | Saves plot data to a file |
---|
| 342 | """ |
---|
| 343 | GuiUtils.saveData1D(plot_data) |
---|
| 344 | |
---|
[570a58f9] | 345 | def onLinearFit(self, id): |
---|
[aadf0af1] | 346 | """ |
---|
| 347 | Creates and displays a simple linear fit for the selected plot |
---|
| 348 | """ |
---|
[570a58f9] | 349 | selected_plot = self.plot_dict[id] |
---|
| 350 | |
---|
| 351 | maxrange = (min(selected_plot.x), max(selected_plot.x)) |
---|
| 352 | fitrange = self.ax.get_xlim() |
---|
| 353 | |
---|
| 354 | fit_dialog = LinearFit(parent=self, |
---|
| 355 | data=selected_plot, |
---|
| 356 | max_range=maxrange, |
---|
| 357 | fit_range=fitrange, |
---|
| 358 | xlabel=self.xLogLabel, |
---|
| 359 | ylabel=self.yLogLabel) |
---|
| 360 | if fit_dialog.exec_() == QtGui.QDialog.Accepted: |
---|
| 361 | return |
---|
[aadf0af1] | 362 | |
---|
| 363 | def onRemovePlot(self, id): |
---|
| 364 | """ |
---|
[570a58f9] | 365 | Responds to the plot delete action |
---|
| 366 | """ |
---|
| 367 | self.removePlot(id) |
---|
| 368 | |
---|
| 369 | if len(self.plot_dict) == 0: |
---|
| 370 | # last plot: graph is empty must be the panel must be destroyed |
---|
| 371 | self.parent.close() |
---|
| 372 | |
---|
| 373 | def removePlot(self, id): |
---|
| 374 | """ |
---|
[aadf0af1] | 375 | Deletes the selected plot from the chart |
---|
| 376 | """ |
---|
[570a58f9] | 377 | if id not in self.plot_dict: |
---|
| 378 | return |
---|
| 379 | |
---|
[aadf0af1] | 380 | selected_plot = self.plot_dict[id] |
---|
| 381 | |
---|
| 382 | plot_dict = copy.deepcopy(self.plot_dict) |
---|
| 383 | |
---|
| 384 | self.plot_dict = {} |
---|
| 385 | |
---|
| 386 | plt.cla() |
---|
| 387 | self.ax.cla() |
---|
| 388 | |
---|
| 389 | for ids in plot_dict: |
---|
| 390 | if ids != id: |
---|
| 391 | self.plot(data=plot_dict[ids], hide_error=plot_dict[ids].hide_error) |
---|
| 392 | |
---|
| 393 | def onFreeze(self, id): |
---|
| 394 | """ |
---|
| 395 | Freezes the selected plot to a separate chart |
---|
| 396 | """ |
---|
| 397 | plot = self.plot_dict[id] |
---|
| 398 | self.manager.add_data(data_list=[plot]) |
---|
| 399 | |
---|
| 400 | def onModifyPlot(self): |
---|
| 401 | """ |
---|
| 402 | Allows for MPL modifications to the selected plot |
---|
| 403 | """ |
---|
| 404 | pass |
---|
| 405 | |
---|
| 406 | def onToggleHideError(self, id): |
---|
| 407 | """ |
---|
| 408 | Toggles hide error/show error menu item |
---|
| 409 | """ |
---|
| 410 | selected_plot = self.plot_dict[id] |
---|
| 411 | current = selected_plot.hide_error |
---|
| 412 | |
---|
| 413 | # Flip the flag |
---|
| 414 | selected_plot.hide_error = not current |
---|
| 415 | |
---|
| 416 | plot_dict = copy.deepcopy(self.plot_dict) |
---|
| 417 | self.plot_dict = {} |
---|
| 418 | |
---|
| 419 | # Clean the canvas |
---|
| 420 | plt.cla() |
---|
| 421 | self.ax.cla() |
---|
| 422 | |
---|
| 423 | # Recreate the plots but reverse the error flag for the current |
---|
| 424 | for ids in plot_dict: |
---|
| 425 | if ids == id: |
---|
| 426 | self.plot(data=plot_dict[ids], hide_error=(not current)) |
---|
| 427 | else: |
---|
| 428 | self.plot(data=plot_dict[ids], hide_error=plot_dict[ids].hide_error) |
---|
| 429 | |
---|
[6d05e1d] | 430 | def xyTransform(self, xLabel="", yLabel=""): |
---|
| 431 | """ |
---|
| 432 | Transforms x and y in View and set the scale |
---|
| 433 | """ |
---|
[570a58f9] | 434 | # Transform all the plots on the chart |
---|
| 435 | for id in self.plot_dict.keys(): |
---|
| 436 | current_plot = self.plot_dict[id] |
---|
| 437 | if current_plot.id == "fit": |
---|
| 438 | self.removePlot(id) |
---|
| 439 | continue |
---|
[fed94a2] | 440 | |
---|
[570a58f9] | 441 | new_xlabel, new_ylabel, xscale, yscale =\ |
---|
| 442 | GuiUtils.xyTransform(current_plot, xLabel, yLabel) |
---|
| 443 | self.xscale = xscale |
---|
| 444 | self.yscale = yscale |
---|
| 445 | self.xLabel = new_xlabel |
---|
| 446 | self.yLabel = new_ylabel |
---|
| 447 | # Plot the updated chart |
---|
| 448 | self.removePlot(id) |
---|
| 449 | self.plot(data=current_plot, marker='o', linestyle='') |
---|
| 450 | |
---|
| 451 | pass # debug hook |
---|
| 452 | |
---|
[fed94a2] | 453 | def onFitDisplay(self, fit_data): |
---|
| 454 | """ |
---|
| 455 | Add a linear fitting line to the chart |
---|
| 456 | """ |
---|
| 457 | # Create new data structure with fitting result |
---|
| 458 | tempx = fit_data[0] |
---|
| 459 | tempy = fit_data[1] |
---|
| 460 | self.fit_result.x = [] |
---|
| 461 | self.fit_result.y = [] |
---|
| 462 | self.fit_result.x = tempx |
---|
| 463 | self.fit_result.y = tempy |
---|
| 464 | self.fit_result.dx = None |
---|
| 465 | self.fit_result.dy = None |
---|
| 466 | |
---|
| 467 | #Remove another Fit, if exists |
---|
| 468 | self.removePlot("fit") |
---|
| 469 | |
---|
| 470 | self.fit_result.reset_view() |
---|
| 471 | #self.offset_graph() |
---|
| 472 | |
---|
| 473 | # Set plot properties |
---|
| 474 | self.fit_result.id = 'fit' |
---|
| 475 | self.fit_result.title = 'Fit' |
---|
| 476 | self.fit_result.name = 'Fit' |
---|
| 477 | |
---|
| 478 | # Plot the line |
---|
| 479 | self.plot(data=self.fit_result, marker='', linestyle='solid', hide_error=True) |
---|
| 480 | |
---|
[c4e5400] | 481 | |
---|
[416fa8f] | 482 | class Plotter(QtGui.QDialog, PlotterWidget): |
---|
| 483 | def __init__(self, parent=None, quickplot=False): |
---|
| 484 | |
---|
| 485 | QtGui.QDialog.__init__(self) |
---|
[aadf0af1] | 486 | PlotterWidget.__init__(self, parent=self, manager=parent, quickplot=quickplot) |
---|
[c4e5400] | 487 | icon = QtGui.QIcon() |
---|
| 488 | icon.addPixmap(QtGui.QPixmap(":/res/ball.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
---|
| 489 | self.setWindowIcon(icon) |
---|
| 490 | |
---|
[416fa8f] | 491 | |
---|