source: sasview/src/sas/qtgui/Plotter.py @ 1042dba

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 1042dba was 1042dba, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Plottables support in the data object. Additional menu items.

  • Property mode set to 100755
File size: 2.5 KB
Line 
1import sys
2from PyQt4 import QtGui
3
4# Replace the qt4agg calls below with qt5 equivalent.
5# Requires some code modifications.
6# https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html
7#
8from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
9from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
10import matplotlib.pyplot as plt
11
12import random
13
14class Plotter(QtGui.QDialog):
15    def __init__(self, parent=None):
16        super(Plotter, self).__init__(parent)
17
18        # a figure instance to plot on
19        self.figure = plt.figure()
20
21        # this is the Canvas Widget that displays the `figure`
22        # it takes the `figure` instance as a parameter to __init__
23        self.canvas = FigureCanvas(self.figure)
24
25        # this is the Navigation widget
26        # it takes the Canvas widget and a parent
27        self.toolbar = NavigationToolbar(self.canvas, self)
28
29        # set the layout
30        layout = QtGui.QVBoxLayout()
31        layout.addWidget(self.canvas)
32        layout.addWidget(self.toolbar)
33        self.setLayout(layout)
34
35        # defaults
36        self._current_plot = 111
37        self._data = []
38        self._title = "Plot"
39        self._id = ""
40        self._xlabel = "X"
41        self._ylabel = "Y"
42        self._ax = self.figure.add_subplot(self._current_plot)
43
44
45    def data(self, data=None):
46        """
47        """
48        self._data = data
49
50    def title(self, title=""):
51        """
52        """
53        self._title = title
54
55    def id(self, id=""):
56        """
57        """
58        self._id = id
59
60    def x_label(self, xlabel=""):
61        """
62        """
63        self._xlabel = xlabel
64
65    def y_label(self, ylabel=""):
66        """
67        """
68        self._ylabel = ylabel
69
70    def clean(self):
71        """
72        """
73        self.figure.delaxes(self._ax)
74        self._ax = self.figure.add_subplot(self._current_plot)
75
76    def plot(self):
77        """
78        plot self._data
79        """
80        # create an axis
81        ax = self._ax
82
83        # plot data with legend
84        ax.plot(self._data.x, self._data.y, '*-', label=self._title)
85
86        # Now add the legend with some customizations.
87        legend = ax.legend(loc='lower left', shadow=True)
88
89        ax.set_ylabel(self._ylabel)
90        ax.set_xlabel(self._xlabel)
91
92        ax.set_yscale('log')
93        ax.set_xscale('log')
94
95        # refresh canvas
96        self.canvas.draw()
Note: See TracBrowser for help on using the repository browser.