def create_plot(self): """ Purpose: create the pythonqwt plot Return: return a list containing the plot and the list of the curves """ plot = Qwt.QwtPlot(self) plot.setCanvasBackground(Qt.black) plot.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time') plot.setAxisScale(Qwt.QwtPlot.xBottom, 0, 10, 1) plot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Temperature') plot.setAxisScale(Qwt.QwtPlot.yLeft, LeftYMIN, LeftYMAX, (LeftYMAX - LeftYMIN) / 5) plot.setAxisTitle(Qwt.QwtPlot.yRight, 'Humidity') plot.setAxisScale(Qwt.QwtPlot.yRight, RightYMIN, RightYMAX, (RightYMAX - RightYMIN) / 5) plot.replot() curve = [None] * 3 pen = [ QPen(QColor('red')), QPen(QColor('green')), QPen(QColor('blue')) ] for i in range(3): curve[i] = Qwt.QwtPlotCurve('') curve[i].setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) pen[i].setWidth(2) curve[i].setPen(pen[i]) curve[i].attach(plot) return plot, curve
def create_plot(self): """ Purpose: create the pyqwt plot Return: return a list containing the plot and the list of the curves """ plot = Qwt.QwtPlot(self) plot.setCanvasBackground(Qt.black) plot.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time [s]') plot.setAxisScale(Qwt.QwtPlot.xBottom, 0, 100, 5) plot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Concentration [ppm]') plot.setAxisScale(Qwt.QwtPlot.yLeft, YMIN, YMAX, (YMAX-YMIN)/10) plot.replot() curve = [None]*3 pen = [QPen(QColor('limegreen')), QPen(QColor('red')) ,QPen(QColor('blue')) ] for i in range(3): curve[i] = Qwt.QwtPlotCurve('') curve[i].setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) pen[i].setWidth(2) curve[i].setPen(pen[i]) curve[i].attach(plot) return plot, curve #--------------------------------------------------- # def create_knob(self): """
def __init__(self, parent=None): super(PlottingDataMonitor, self).__init__(parent) self.monitor_active = False self.com_monitor = None self.livefeed = LiveDataFeed() self.temperature_samples = [] self.timer = QTimer() # menu # self.file_menu = self.menuBar().addMenu("&File") selectport_action = QAction('Select TTY &Port...', self) selectport_action.triggered.connect(self.on_select_port) self.file_menu.addAction(selectport_action) self.start_action = QAction('&Start monitor') self.start_action.triggered.connect(self.on_start) self.start_action.setEnabled(False) self.file_menu.addAction(self.start_action) self.stop_action = QAction('&Stop monitor') self.stop_action.triggered.connect(self.on_stop) # main widget # # port portname_label = QLabel('tty port:') self.portname = QLineEdit() self.portname.setEnabled(False) self.portname.setFrame(False) portname_layout = QHBoxLayout() portname_layout.addWidget(portname_label) portname_layout.addWidget(self.portname, 0) portname_layout.addStretch(1) portname_groupbox = QGroupBox('Port') portname_groupbox.setLayout(portname_layout) # plot widget self.plot = qwt.QwtPlot(self) self.plot.setCanvasBackground(Qt.black) self.plot.setAxisTitle(qwt.QwtPlot.xBottom, 'Time') self.plot.setAxisScale(qwt.QwtPlot.xBottom, 0, 10, 1) self.plot.setAxisTitle(qwt.QwtPlot.yLeft, 'Temperature') self.plot.setAxisScale(qwt.QwtPlot.yLeft, 0, 250, 40) self.plot.replot() # curve widget self.curve = qwt.QwtPlotCurve('') self.curve.setRenderHint(qwt.QwtPlotItem.RenderAntialiased) pen = QPen(QColor('limegreen')) pen.setWidth(2) self.curve.setPen(pen) self.curve.attach(self.plot) # dial # self.dial = QDial() self.dial.setNotchesVisible(True) self.dial.setRange(0, 20) self.dial.setValue(10) self.dial.valueChanged.connect(self.on_dial_change) self.dial_label = QLabel('Update speed = %s (Hz)' % self.dial.value()) self.dial_label.setAlignment(Qt.AlignTop | Qt.AlignHCenter) dial_layout = QVBoxLayout() dial_layout.addWidget(self.dial) dial_layout.addWidget(self.dial_label) # plot layout plot_layout = QVBoxLayout() plot_layout.addWidget(self.plot) plot_layout.addLayout(dial_layout) plot_groupbox = QGroupBox('Temperature') plot_groupbox.setLayout(plot_layout) # main self.main_frame = QWidget() main_layout = QVBoxLayout() main_layout.addWidget(portname_groupbox) main_layout.addWidget(plot_groupbox) main_layout.addStretch(1) self.main_frame.setLayout(main_layout) self.setCentralWidget(self.main_frame) # status # self.status_text = QLabel('Monitor idle') self.statusBar().addWidget(self.status_text, 1)
import qwt import numpy as np app = qtpy.QtGui.QApplication([]) x = np.linspace(-10, 10, 500) plot = qwt.QwtPlot("Trigonometric functions") plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend) qwt.QwtPlotCurve.make(x, np.cos(x), "Cosinus", plot, linecolor="red", antialiased=True) qwt.QwtPlotCurve.make(x, np.sin(x), "Sinus", plot, linecolor="blue", antialiased=True) plot.resize(600, 300) plot.show() import os.path as osp plot.grab().save( osp.join(osp.abspath(osp.dirname(__file__)), "images", "QwtPlot_example.png")) app.exec_()
pen.setJoinStyle(QC.Qt.MiterJoin) symbol = qwt.QwtSymbol() symbol.setPen(pen) symbol.setBrush(QC.Qt.red) symbol.setPath(path) symbol.setPinPoint(QC.QPointF(0.0, 0.0)) symbol.setSize(10, 14) # --- Test it within a simple plot --- curve = qwt.QwtPlotCurve() curve_pen = QG.QPen(QC.Qt.blue) curve_pen.setStyle(QC.Qt.DotLine) curve.setPen(curve_pen) curve.setSymbol(symbol) x = np.linspace(0, 10, 10) curve.setData(x, np.sin(x)) plot = qwt.QwtPlot() curve.attach(plot) plot.resize(600, 300) plot.replot() plot.show() plot.grab().save( osp.join(osp.abspath(osp.dirname(__file__)), "images", "symbol_path_example.png") ) app.exec_()