1 | import logging |
---|
2 | import copy |
---|
3 | import numpy |
---|
4 | import pylab |
---|
5 | |
---|
6 | from 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 | # |
---|
12 | from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas |
---|
13 | from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar |
---|
14 | import matplotlib.pyplot as plt |
---|
15 | |
---|
16 | DEFAULT_CMAP = pylab.cm.jet |
---|
17 | |
---|
18 | import sas.qtgui.PlotUtilities as PlotUtilities |
---|
19 | import sas.qtgui.PlotHelper as PlotHelper |
---|
20 | from sas.qtgui.PlotterBase import PlotterBase |
---|
21 | |
---|
22 | class 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() |
---|