Changeset 87cc73a in sasview for src/sas/qtgui/Plotter.py
- Timestamp:
- Jan 11, 2017 9:31:58 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- db5cd8d
- Parents:
- b46f285
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotter.py
rb46f285 r87cc73a 13 13 from sas.qtgui.SetGraphRange import SetGraphRange 14 14 from sas.qtgui.LinearFit import LinearFit 15 from sas.qtgui.PlotProperties import PlotProperties 16 import sas.qtgui.PlotUtilities as PlotUtilities 15 17 16 18 class PlotterWidget(PlotterBase): … … 59 61 self.title(title=value.name) 60 62 61 def plot(self, data=None, marker=None, linestyle=None, hide_error=False):63 def plot(self, data=None, color=None, marker=None, hide_error=False): 62 64 """ 63 65 Add a new plot of self._data to the chart. … … 68 70 assert(self._data) 69 71 70 is_fit = (self. _data.id=="fit")71 72 # Shortcut for the current axis72 is_fit = (self.data.id=="fit") 73 74 # Shortcuts 73 75 ax = self.ax 74 75 if marker == None: 76 marker = 'o' 77 78 if linestyle == None: 79 linestyle = '' 80 81 if not self._title: 82 self.title(title=self.data.name) 83 84 # plot data with/without errorbars 85 if hide_error: 86 line = ax.plot(self._data.view.x, self._data.view.y, 87 marker=marker, 88 linestyle=linestyle, 89 label=self._title, 90 picker=True) 76 x = self._data.view.x 77 y = self._data.view.y 78 79 # Marker symbol. Passed marker is one of matplotlib.markers characters 80 # Alternatively, picked up from Data1D as an int index of PlotUtilities.SHAPES dict 81 if marker is None: 82 marker = self.data.symbol 83 marker = PlotUtilities.SHAPES.values()[marker] 84 85 # Plot name 86 self.title(title=self.data.title) 87 88 # Error marker toggle 89 if hide_error is None: 90 hide_error = self.data.hide_error 91 92 # Plot color 93 if color is None: 94 color = self.data.custom_color 95 96 color = PlotUtilities.getValidColor(color) 97 98 markersize = self._data.markersize 99 100 # Draw non-standard markers 101 l_width = markersize * 0.4 102 if marker == '-' or marker == '--': 103 line = self.ax.plot(x, y, color=color, lw=l_width, marker='', 104 linestyle=marker, label=self._title, zorder=10)[0] 105 106 elif marker == 'vline': 107 y_min = min(y)*9.0/10.0 if min(y) < 0 else 0.0 108 line = self.ax.vlines(x=x, ymin=y_min, ymax=y, color=color, 109 linestyle='-', label=self._title, lw=l_width, zorder=1) 110 111 elif marker == 'step': 112 line = self.ax.step(x, y, color=color, marker='', linestyle='-', 113 label=self._title, lw=l_width, zorder=1)[0] 114 91 115 else: 92 line = ax.errorbar(self._data.view.x, self._data.view.y, 93 yerr=self._data.view.dy, xerr=None, 94 capsize=2, linestyle='', 95 barsabove=False, 96 marker=marker, 97 lolims=False, uplims=False, 98 xlolims=False, xuplims=False, 99 label=self._title, 100 picker=True) 116 # plot data with/without errorbars 117 if hide_error: 118 line = ax.plot(x, y, marker=marker, color=color, markersize=markersize, 119 linestyle='', label=self._title, picker=True) 120 else: 121 line = ax.errorbar(x, y, 122 yerr=self._data.view.dy, xerr=None, 123 capsize=2, linestyle='', 124 barsabove=False, 125 color=color, 126 marker=marker, 127 markersize=markersize, 128 lolims=False, uplims=False, 129 xlolims=False, xuplims=False, 130 label=self._title, 131 picker=True) 101 132 102 133 # Update the list of data sets (plots) in chart … … 112 143 if self.x_label and not is_fit: 113 144 ax.set_xlabel(self.x_label) 114 115 # Title only for regular charts116 if not self.quickplot and not is_fit:117 ax.set_title(label=self._title)118 145 119 146 # Include scaling (log vs. linear) … … 170 197 for id in self.plot_dict.keys(): 171 198 plot = self.plot_dict[id] 172 name = plot.name 199 #name = plot.name 200 name = plot.title 173 201 plot_menu = self.contextMenu.addMenu('&%s' % name) 174 202 … … 210 238 211 239 self.actionModifyPlot = plot_menu.addAction('&Modify Plot Property') 212 self.actionModifyPlot.triggered.connect(self.onModifyPlot) 240 self.actionModifyPlot.triggered.connect( 241 functools.partial(self.onModifyPlot, id)) 213 242 214 243 def createContextMenuQuick(self): … … 361 390 return 362 391 392 def replacePlot(self, id, new_plot): 393 """ 394 Remove plot 'id' and add 'new_plot' to the chart. 395 This effectlvely refreshes the chart with changes to one of its plots 396 """ 397 self.removePlot(id) 398 self.plot(data=new_plot) 399 363 400 def onRemovePlot(self, id): 364 401 """ … … 407 444 self.manager.add_data(data_list=[plot]) 408 445 409 def onModifyPlot(self ):446 def onModifyPlot(self, id): 410 447 """ 411 448 Allows for MPL modifications to the selected plot 412 449 """ 413 pass 450 selected_plot = self.plot_dict[id] 451 current = selected_plot.hide_error 452 453 # Old style color - single integer for enum color 454 # New style color - #hhhhhh 455 color = selected_plot.custom_color 456 # marker symbol and size 457 marker = selected_plot.symbol 458 marker_size = selected_plot.markersize 459 # plot name 460 legend = selected_plot.title 461 462 plotPropertiesWidget = PlotProperties(self, 463 color=color, 464 marker=marker, 465 marker_size=marker_size, 466 legend=legend) 467 if plotPropertiesWidget.exec_() == QtGui.QDialog.Accepted: 468 marker = plotPropertiesWidget.marker() 469 marker_size = plotPropertiesWidget.markersize() 470 color = plotPropertiesWidget.color() 471 legend = plotPropertiesWidget.legend() 472 473 # Update Data1d 474 selected_plot.markersize = marker_size 475 selected_plot.custom_color = color 476 selected_plot.symbol = marker 477 selected_plot.title = legend 478 479 # Redraw the plot 480 self.replacePlot(id, selected_plot) 414 481 415 482 def onToggleHideError(self, id): … … 461 528 # Directly overwrite the data to avoid label reassignment 462 529 self._data = current_plot 463 self.plot( marker='o', linestyle='')530 self.plot() 464 531 465 532 pass # debug hook … … 491 558 492 559 # Plot the line 493 self.plot(data=self.fit_result, marker=' ', linestyle='solid', hide_error=True)560 self.plot(data=self.fit_result, marker='-', hide_error=True) 494 561 495 562
Note: See TracChangeset
for help on using the changeset viewer.