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:
1.8 KB
|
Line | |
---|
1 | import logging |
---|
2 | |
---|
3 | from PyQt4 import QtGui |
---|
4 | |
---|
5 | # TODO: Replace the qt4agg calls below with qt5 equivalent. |
---|
6 | # Requires some code modifications. |
---|
7 | # https://www.boxcontrol.net/embedding-matplotlib-plot-on-pyqt5-gui.html |
---|
8 | # |
---|
9 | from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas |
---|
10 | from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar |
---|
11 | import matplotlib.pyplot as plt |
---|
12 | import matplotlib as mpl |
---|
13 | |
---|
14 | import sas.qtgui.PlotHelper as PlotHelper |
---|
15 | from sas.qtgui.PlotterBase import PlotterBase |
---|
16 | |
---|
17 | class Plotter(PlotterBase): |
---|
18 | def __init__(self, parent=None, quickplot=False): |
---|
19 | super(Plotter, self).__init__(parent, quickplot=quickplot) |
---|
20 | |
---|
21 | @property |
---|
22 | def data(self): |
---|
23 | return self._data |
---|
24 | |
---|
25 | @data.setter |
---|
26 | def data(self, value): |
---|
27 | """ data setter """ |
---|
28 | self._data = value |
---|
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) |
---|
33 | |
---|
34 | def plot(self, marker=None, linestyle=None): |
---|
35 | """ |
---|
36 | Plot self._data |
---|
37 | """ |
---|
38 | # create an axis |
---|
39 | ax = self.ax |
---|
40 | |
---|
41 | if marker == None: |
---|
42 | marker = '*' |
---|
43 | |
---|
44 | if linestyle == None: |
---|
45 | linestyle = '-' |
---|
46 | |
---|
47 | # plot data with legend |
---|
48 | ax.plot(self._data.x, self._data.y, marker=marker, linestyle=linestyle, label=self.title) |
---|
49 | |
---|
50 | # Now add the legend with some customizations. |
---|
51 | legend = ax.legend(loc='upper right', shadow=True) |
---|
52 | |
---|
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) |
---|
58 | |
---|
59 | ax.set_yscale('log') |
---|
60 | ax.set_xscale('log') |
---|
61 | |
---|
62 | # refresh canvas |
---|
63 | self.canvas.draw() |
---|
64 | |
---|
Note: See
TracBrowser
for help on using the repository browser.