Changeset ef01be4 in sasview for src/sas/qtgui/Plotter.py
- Timestamp:
- Dec 2, 2016 4:28:23 AM (8 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:
- b94889a
- Parents:
- ded2ce3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotter.py
r31c5b58 ref01be4 10 10 from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar 11 11 import matplotlib.pyplot as plt 12 import matplotlib as mpl 12 13 13 14 import sas.qtgui.PlotHelper as PlotHelper 15 from sas.qtgui.PlotterBase import PlotterBase 14 16 15 class Plotter(QtGui.QDialog): 16 def __init__(self, parent=None): 17 super(Plotter, self).__init__(parent) 18 19 # Required for the communicator 20 self.parent = parent 21 22 # a figure instance to plot on 23 self.figure = plt.figure() 24 25 # this is the Canvas Widget that displays the `figure` 26 # it takes the `figure` instance as a parameter to __init__ 27 self.canvas = FigureCanvas(self.figure) 28 29 # this is the Navigation widget 30 # it takes the Canvas widget and a parent 31 self.toolbar = NavigationToolbar(self.canvas, self) 32 33 # set the layout 34 layout = QtGui.QVBoxLayout() 35 layout.addWidget(self.canvas) 36 layout.addWidget(self.toolbar) 37 self.setLayout(layout) 38 39 # defaults 40 self._current_plot = 111 41 self._data = [] 42 self._title = "Plot" 43 self._id = "" 44 self._xlabel = "X" 45 self._ylabel = "Y" 46 self._ax = self.figure.add_subplot(self._current_plot) 47 48 # Notify the helper 49 PlotHelper.addPlot(self) 50 # Notify the listeners 51 self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 17 class Plotter(PlotterBase): 18 def __init__(self, parent=None, quickplot=False): 19 super(Plotter, self).__init__(parent, quickplot=quickplot) 52 20 53 21 @property 54 22 def data(self): 55 """ data getter """56 23 return self._data 57 24 … … 60 27 """ data setter """ 61 28 self._data = value 62 63 def title(self, title=""): 64 """ title setter """ 65 self._title = title 66 67 def id(self, id=""): 68 """ id setter """ 69 self._id = id 70 71 def x_label(self, xlabel=""): 72 """ x-label setter """ 73 self._xlabel = xlabel 74 75 def y_label(self, ylabel=""): 76 """ y-label setter """ 77 self._ylabel = ylabel 78 79 def clean(self): 80 """ 81 Redraw the graph 82 """ 83 self.figure.delaxes(self._ax) 84 self._ax = self.figure.add_subplot(self._current_plot) 29 self.label=value.name 30 self.xLabel(xlabel="%s(%s)"%(value._xaxis, value._xunit)) 31 self.yLabel(ylabel="%s(%s)"%(value._yaxis, value._yunit)) 32 self.title(title=value.title) 85 33 86 34 def plot(self, marker=None, linestyle=None): … … 89 37 """ 90 38 # create an axis 91 ax = self. _ax39 ax = self.ax 92 40 93 41 if marker == None: … … 98 46 99 47 # plot data with legend 100 ax.plot(self._data.x, self._data.y, marker=marker, linestyle=linestyle, label=self. _title)48 ax.plot(self._data.x, self._data.y, marker=marker, linestyle=linestyle, label=self.title) 101 49 102 50 # Now add the legend with some customizations. 103 legend = ax.legend(loc=' lower left', shadow=True)51 legend = ax.legend(loc='upper right', shadow=True) 104 52 105 ax.set_ylabel(self._ylabel) 106 ax.set_xlabel(self._xlabel) 53 ax.set_ylabel(self.y_label) 54 ax.set_xlabel(self.x_label) 55 # Title only for regular charts 56 if not self.quickplot: 57 ax.set_title(label=self.title) 107 58 108 59 ax.set_yscale('log') … … 112 63 self.canvas.draw() 113 64 114 def closeEvent(self, event):115 """116 Overwrite the close event adding helper notification117 """118 # Please remove me from your database.119 PlotHelper.deletePlot(PlotHelper.idOfPlot(self))120 # Notify the listeners121 self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots())122 event.accept()123
Note: See TracChangeset
for help on using the changeset viewer.