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')
105 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
106 self.setMinimumSize(1,1)
107 self.updateGeometry()
115 Deal with "ValueError: bottom cannot be >= top" bug in older matplotlib versions
119 - https://github.com/matplotlib/matplotlib/pull/10915
120 - https://github.com/ros-visualization/rqt_plot/issues/35
123 self.figure.tight_layout()
128 limits_changed = Signal()
131 super(MatDataPlot, self).
__init__(parent)
146 def add_curve(self, curve_id, curve_name, curve_color=QColor(Qt.blue), markers_on=
False):
155 line = self.
_canvas.axes.plot([], [],
'o-', markersize=marker_size, label=curve_name,
156 linewidth=1, picker=5, color=curve_color.name())[0]
163 curve_id = str(curve_id)
165 self.
_curves[curve_id].remove()
170 handles, labels = self.
_canvas.axes.get_legend_handles_labels()
172 hl = sorted(zip(handles, labels), key=operator.itemgetter(1))
173 handles, labels = zip(*hl)
174 self.
_canvas.axes.legend(handles, labels, loc=
'upper left')
178 line.set_data(data_x, data_y)
181 self.
_canvas.axes.grid(
True, color=
'gray')
186 matcolor = (color[0] / 255.0, color[1] / 255.0, color[2] / 255.0)
192 self.
_canvas.axes.set_xbound(lower=limits[0], upper=limits[1])
195 self.
_canvas.axes.set_ybound(lower=limits[0], upper=limits[1])
198 return list(self.
_canvas.axes.get_xbound())
201 return list(self.
_canvas.axes.get_ybound())