Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 from python_qt_binding.QtCore import Slot, Qt, qWarning, Signal
00034 from python_qt_binding.QtGui import QColor, QVBoxLayout, QWidget
00035
00036 from pyqtgraph import PlotWidget, mkPen, mkBrush
00037 import numpy
00038
00039
00040 class PyQtGraphDataPlot(QWidget):
00041
00042 limits_changed = Signal()
00043
00044 def __init__(self, parent=None):
00045 super(PyQtGraphDataPlot, self).__init__(parent)
00046 self._plot_widget = PlotWidget()
00047 self._plot_widget.getPlotItem().addLegend()
00048 self._plot_widget.setBackground((255, 255, 255))
00049 self._plot_widget.setXRange(0, 10, padding=0)
00050 vbox = QVBoxLayout()
00051 vbox.addWidget(self._plot_widget)
00052 self.setLayout(vbox)
00053 self._plot_widget.getPlotItem().sigRangeChanged.connect(self.limits_changed)
00054
00055 self._curves = {}
00056 self._current_vline = None
00057
00058 def add_curve(self, curve_id, curve_name, curve_color=QColor(Qt.blue), markers_on=False):
00059 pen = mkPen(curve_color, width=1)
00060 symbol = "o"
00061 symbolPen = mkPen(QColor(Qt.black))
00062 symbolBrush = mkBrush(curve_color)
00063
00064 if markers_on:
00065 plot = self._plot_widget.plot(name=curve_name, pen=pen, symbol=symbol, symbolPen=symbolPen, symbolBrush=symbolBrush, symbolSize=4)
00066 else:
00067 plot = self._plot_widget.plot(name=curve_name, pen=pen)
00068 self._curves[curve_id] = plot
00069
00070 def remove_curve(self, curve_id):
00071 curve_id = str(curve_id)
00072 if curve_id in self._curves:
00073 self._plot_widget.removeItem(self._curves[curve_id])
00074 del self._curves[curve_id]
00075 self._update_legend()
00076
00077 def _update_legend(self):
00078
00079 self._plot_widget.clear()
00080 self._plot_widget.getPlotItem().legend.items = []
00081 for curve in self._curves.values():
00082 self._plot_widget.addItem(curve)
00083 if self._current_vline:
00084 self._plot_widget.addItem(self._current_vline)
00085
00086 def redraw(self):
00087 pass
00088
00089 def set_values(self, curve_id, data_x, data_y):
00090 curve = self._curves[curve_id]
00091 curve.setData(data_x, data_y)
00092
00093 def vline(self, x, color):
00094 if self._current_vline:
00095 self._plot_widget.removeItem(self._current_vline)
00096 self._current_vline = self._plot_widget.addLine(x=x, pen=color)
00097
00098 def set_xlim(self, limits):
00099
00100 self._plot_widget.setXRange(limits[0], limits[1], padding=0)
00101
00102 def set_ylim(self, limits):
00103 self._plot_widget.setYRange(limits[0], limits[1], padding=0)
00104
00105 def get_xlim(self):
00106 x_range, _ = self._plot_widget.viewRange()
00107 return x_range
00108
00109 def get_ylim(self):
00110 _, y_range = self._plot_widget.viewRange()
00111 return y_range