33 from python_qt_binding
import QT_BINDING, QT_BINDING_VERSION
36 from pkg_resources
import parse_version
41 return [int(x)
for x
in re.sub(
r'(\.0+)*$',
'', s).split(
'.')]
43 if QT_BINDING ==
'pyside':
44 qt_binding_version = QT_BINDING_VERSION.replace(
'~',
'-')
46 raise ImportError(
'A PySide version newer than 1.1.0 is required.')
48 from python_qt_binding.QtCore
import Slot, Qt, qVersion, qWarning, Signal
49 from python_qt_binding.QtGui
import QColor
50 from python_qt_binding.QtWidgets
import QWidget, QVBoxLayout, QSizePolicy
54 if qVersion().startswith(
'5.'):
55 if QT_BINDING ==
'pyside':
57 raise ImportError(
'A newer matplotlib is required (at least 2.1.0 for PySide 2)')
59 raise ImportError(
'A newer matplotlib is required (at least 1.4.0 for Qt 5)')
61 matplotlib.use(
'Qt5Agg')
62 from matplotlib.backends.backend_qt5agg
import FigureCanvasQTAgg
as FigureCanvas
67 sys.modules[
'_thread'] = thread
68 from matplotlib.backends.backend_qt5agg
import FigureCanvasQTAgg
as FigureCanvas
69 from matplotlib.backends.backend_qt5agg
import NavigationToolbar2QT
as NavigationToolbar
70 elif qVersion().startswith(
'4.'):
72 raise ImportError(
'A newer matplotlib is required (at least 1.1.0 for Qt 4)')
74 matplotlib.use(
'Qt4Agg')
75 from matplotlib.backends.backend_qt4agg
import FigureCanvasQTAgg
as FigureCanvas
80 sys.modules[
'_thread'] = thread
81 from matplotlib.backends.backend_qt4agg
import FigureCanvasQTAgg
as FigureCanvas
83 from matplotlib.backends.backend_qt4agg
import NavigationToolbar2QTAgg
as NavigationToolbar
85 from matplotlib.backends.backend_qt4agg
import NavigationToolbar2QT
as NavigationToolbar
87 raise NotImplementedError(
'Unsupport Qt version: %s' % qVersion())
89 from matplotlib.figure
import Figure
98 """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).""" 102 self.
axes = self.figure.add_subplot(111)
103 self.axes.grid(
True, color=
'gray')
104 self.figure.tight_layout()
105 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
106 self.updateGeometry()
110 self.figure.tight_layout()
112 limits_changed = Signal()
115 super(MatDataPlot, self).
__init__(parent)
128 self.limits_changed.emit()
130 def add_curve(self, curve_id, curve_name, curve_color=QColor(Qt.blue), markers_on=
False):
139 line = self._canvas.axes.plot([], [],
'o-', markersize=marker_size, label=curve_name,
140 linewidth=1, picker=5, color=curve_color.name())[0]
147 curve_id = str(curve_id)
149 self.
_curves[curve_id].remove()
154 handles, labels = self._canvas.axes.get_legend_handles_labels()
156 hl = sorted(zip(handles, labels), key=operator.itemgetter(1))
157 handles, labels = zip(*hl)
158 self._canvas.axes.legend(handles, labels, loc=
'upper left')
162 line.set_data(data_x, data_y)
165 self._canvas.axes.grid(
True, color=
'gray')
170 matcolor = (color[0] / 255.0, color[1] / 255.0, color[2] / 255.0)
172 self._current_vline.remove()
173 self.
_current_vline = self._canvas.axes.axvline(x=x, color=matcolor)
176 self._canvas.axes.set_xbound(lower=limits[0], upper=limits[1])
179 self._canvas.axes.set_ybound(lower=limits[0], upper=limits[1])
182 return list(self._canvas.axes.get_xbound())
185 return list(self._canvas.axes.get_ybound())
def add_curve(self, curve_id, curve_name, curve_color=QColor(Qt.blue), markers_on=False)
def resizeEvent(self, event)
def vline(self, x, color)
def remove_curve(self, curve_id)
def __init__(self, parent=None)
def set_values(self, curve, data_x, data_y)
def __init__(self, parent=None)
def _limits_changed(self, event)
def set_ylim(self, limits)
def set_xlim(self, limits)