source: sasview/src/sas/qtgui/Plotter2D.py @ b94889a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b94889a was ef01be4, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

More context menu functionality in plots - SASVIEW-167

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import logging
2import copy
3import numpy
4import pylab
5
6from PyQt4 import QtGui
7
8# TODO: Replace the qt4agg calls below with qt5 equivalent.
9# Requires some code modifications.
10# https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html
11#
12from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
13from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
14import matplotlib.pyplot as plt
15
16DEFAULT_CMAP = pylab.cm.jet
17
18import sas.qtgui.PlotUtilities as PlotUtilities
19import sas.qtgui.PlotHelper as PlotHelper
20from sas.qtgui.PlotterBase import PlotterBase
21
22class Plotter2D(PlotterBase):
23    def __init__(self, parent=None, quickplot=False):
24        super(Plotter2D, self).__init__(parent, quickplot=quickplot)
25
26    @property
27    def data(self):
28        return self._data
29
30    @data.setter
31    def data(self, data=None):
32        """ data setter """
33        self._data = data
34        self.qx_data=data.qx_data
35        self.qy_data=data.qy_data
36        self.xmin=data.xmin
37        self.xmax=data.xmax
38        self.ymin=data.ymin
39        self.ymax=data.ymax
40        self.zmin=data.zmin
41        self.zmax=data.zmax
42        self.label=data.name
43        self.xLabel(xlabel="%s(%s)"%(data._xaxis, data._xunit))
44        self.yLabel(ylabel="%s(%s)"%(data._yaxis, data._yunit))
45        self.title(title=data.title)
46
47    def plot(self, marker=None, linestyle=None):
48        """
49        Plot 2D self._data
50        """
51        # create an axis object
52        ax = self.ax
53
54        # graph properties
55        ax.set_xlabel(self.x_label)
56        ax.set_ylabel(self.y_label)
57        # Title only for regular charts
58        if not self.quickplot:
59            ax.set_title(label=self.title)
60
61        # Re-adjust colorbar
62        self.figure.subplots_adjust(left=0.2, right=.8, bottom=.2)
63
64        output = PlotUtilities.build_matrix(self._data.data, self.qx_data, self.qy_data)
65
66        im = ax.imshow(output,
67                       interpolation='nearest',
68                       origin='lower',
69                       vmin=self.zmin, vmax=self.zmax,
70                       cmap=self.cmap,
71                       extent=(self.xmin, self.xmax,
72                               self.ymin, self.ymax))
73
74        cbax = self.figure.add_axes([0.84, 0.2, 0.02, 0.7])
75        cb = self.figure.colorbar(im, cax=cbax)
76        cb.update_bruteforce(im)
77        cb.set_label('$' + self._scale + '$')
78
79        # Schedule the draw for the next time the event loop is idle.
80        self.canvas.draw_idle()
Note: See TracBrowser for help on using the repository browser.