Changeset ef01be4 in sasview for src/sas/qtgui/Plotter.py


Ignore:
Timestamp:
Dec 2, 2016 4:28:23 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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
Message:

More context menu functionality in plots - SASVIEW-167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotter.py

    r31c5b58 ref01be4  
    1010from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar 
    1111import matplotlib.pyplot as plt 
     12import matplotlib as mpl 
    1213 
    1314import sas.qtgui.PlotHelper as PlotHelper 
     15from sas.qtgui.PlotterBase import PlotterBase 
    1416 
    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()) 
     17class Plotter(PlotterBase): 
     18    def __init__(self, parent=None, quickplot=False): 
     19        super(Plotter, self).__init__(parent, quickplot=quickplot) 
    5220 
    5321    @property 
    5422    def data(self): 
    55         """ data getter """ 
    5623        return self._data 
    5724 
     
    6027        """ data setter """ 
    6128        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) 
    8533 
    8634    def plot(self, marker=None, linestyle=None): 
     
    8937        """ 
    9038        # create an axis 
    91         ax = self._ax 
     39        ax = self.ax 
    9240 
    9341        if marker == None: 
     
    9846 
    9947        # 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) 
    10149 
    10250        # 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) 
    10452 
    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) 
    10758 
    10859        ax.set_yscale('log') 
     
    11263        self.canvas.draw() 
    11364 
    114     def closeEvent(self, event): 
    115         """ 
    116         Overwrite the close event adding helper notification 
    117         """ 
    118         # Please remove me from your database. 
    119         PlotHelper.deletePlot(PlotHelper.idOfPlot(self)) 
    120         # Notify the listeners 
    121         self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) 
    122         event.accept() 
    123  
Note: See TracChangeset for help on using the changeset viewer.