Changeset 87cc73a in sasview for src/sas/qtgui/Plotter.py


Ignore:
Timestamp:
Jan 11, 2017 9:31:58 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:
db5cd8d
Parents:
b46f285
Message:

Added Modify Plot Properties functionality. SASVIEW-169

File:
1 edited

Legend:

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

    rb46f285 r87cc73a  
    1313from sas.qtgui.SetGraphRange import SetGraphRange 
    1414from sas.qtgui.LinearFit import LinearFit 
     15from sas.qtgui.PlotProperties import PlotProperties 
     16import sas.qtgui.PlotUtilities as PlotUtilities 
    1517 
    1618class PlotterWidget(PlotterBase): 
     
    5961        self.title(title=value.name) 
    6062 
    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): 
    6264        """ 
    6365        Add a new plot of self._data to the chart. 
     
    6870        assert(self._data) 
    6971 
    70         is_fit = (self._data.id=="fit") 
    71  
    72         # Shortcut for the current axis 
     72        is_fit = (self.data.id=="fit") 
     73 
     74        # Shortcuts 
    7375        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 
    91115        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) 
    101132 
    102133        # Update the list of data sets (plots) in chart 
     
    112143        if self.x_label and not is_fit: 
    113144            ax.set_xlabel(self.x_label) 
    114  
    115         # Title only for regular charts 
    116         if not self.quickplot and not is_fit: 
    117             ax.set_title(label=self._title) 
    118145 
    119146        # Include scaling (log vs. linear) 
     
    170197        for id in self.plot_dict.keys(): 
    171198            plot = self.plot_dict[id] 
    172             name = plot.name 
     199            #name = plot.name 
     200            name = plot.title 
    173201            plot_menu = self.contextMenu.addMenu('&%s' % name) 
    174202 
     
    210238 
    211239            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)) 
    213242 
    214243    def createContextMenuQuick(self): 
     
    361390            return 
    362391 
     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 
    363400    def onRemovePlot(self, id): 
    364401        """ 
     
    407444        self.manager.add_data(data_list=[plot]) 
    408445 
    409     def onModifyPlot(self): 
     446    def onModifyPlot(self, id): 
    410447        """ 
    411448        Allows for MPL modifications to the selected plot 
    412449        """ 
    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) 
    414481 
    415482    def onToggleHideError(self, id): 
     
    461528            # Directly overwrite the data to avoid label reassignment 
    462529            self._data = current_plot 
    463             self.plot(marker='o', linestyle='') 
     530            self.plot() 
    464531 
    465532        pass # debug hook 
     
    491558 
    492559        # 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) 
    494561 
    495562 
Note: See TracChangeset for help on using the changeset viewer.