Fix double axis layout
This commit is contained in:
parent
76f04c1ae3
commit
98f3475d97
@ -5,7 +5,7 @@ from PyQt6.QtGui import QIcon
|
||||
from .widgets.menubar import MenuBar
|
||||
from .widgets.toolbar import ToolBar
|
||||
from .widgets.statusbar import StatusBar
|
||||
from .widgets.metadata_input import MetadataInput
|
||||
from .widgets.metadata_input import MetadataInput2
|
||||
from .widgets.plot import Plot
|
||||
from .widgets.device_select import ListChoice
|
||||
# from .widgets.treeview import TreeView
|
||||
@ -55,12 +55,8 @@ class MainWindow(QMainWindow):
|
||||
self.setMenuBar(MenuBar(self))
|
||||
self.setStatusBar(StatusBar(self))
|
||||
|
||||
# layout.addWidget(self.treeview)
|
||||
layout.addWidget(self.editbox, stretch=1)
|
||||
layout.addWidget(self.editbox)
|
||||
|
||||
init_elements = [("name1", "val1"), ("name2", "val2")]
|
||||
layout.addWidget(MetadataInput(init_elements))
|
||||
init_elements = [("name1", "val1"), ("name2", "val2"), ("interval", 0.5)]
|
||||
layout.addWidget(MetadataInput2(init_elements))
|
||||
self.plot_widget = Plot()
|
||||
layout.addWidget(self.plot_widget)
|
||||
|
||||
@ -236,7 +232,7 @@ class MainWindow(QMainWindow):
|
||||
i, tval, vval, led_val = current_data
|
||||
print(f"Data {i:03}: {tval}s, {vval}V, {led_val}%")
|
||||
# update the plot
|
||||
self.plot_widget.update(tval, vval, led_val)
|
||||
self.plot_widget.update_plot(tval, vval, led_val)
|
||||
|
||||
def measurement_is_running(self):
|
||||
return self.proc_measure is not None
|
||||
@ -269,3 +265,6 @@ class MainWindow(QMainWindow):
|
||||
"""
|
||||
Event handler for the "Settings" button. Displays the "Settings" window.
|
||||
"""
|
||||
|
||||
def __del__(self):
|
||||
self.measure_stop()
|
||||
|
@ -1,24 +1,46 @@
|
||||
import pyqtgraph as pg
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
|
||||
class Plot(pg.PlotWidget):
|
||||
class Plot(pg.GraphicsLayoutWidget):
|
||||
"""
|
||||
pyqtgraph plot widget for showing voltage and LED vs time
|
||||
"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("CPD - LED")
|
||||
# self.x_axis.setLabel("Time [s]")
|
||||
# self.v_axis.setLabel("CPD [V]")
|
||||
# self.l_axis.setLabel("LED [%]")
|
||||
# self.layout.addItem(self.x_axis, row=1, col=1, rowspan=1, colspan=1)
|
||||
# self.layout.addItem(self.v_axis, row=1, col=1, rowspan=1, colspan=1)
|
||||
self.v_plot_item = pg.PlotItem()
|
||||
self.v_box = self.v_plot_item.vb
|
||||
self.addItem(self.v_plot_item, row=1, col=1)
|
||||
|
||||
self.v_plot_item.showAxis('right')
|
||||
self.v_plot_item.setLabel('right', "LED [%]")
|
||||
self.v_plot_item.setLabel('left', "CPD [V]")
|
||||
self.v_plot_item.setLabel('bottom', "time [s]")
|
||||
|
||||
self.l_box = pg.ViewBox()
|
||||
self.v_plot_item.scene().addItem(self.l_box)
|
||||
self.v_plot_item.getAxis('right').linkToView(self.l_box)
|
||||
self.l_box.setXLink(self.v_plot_item)
|
||||
self.l_box.setYRange(0, 110)
|
||||
|
||||
self.setBackground("w")
|
||||
self.setTitle("Test")
|
||||
self.setLabel("bottom", "time [s]")
|
||||
self.setLabel("left", "Voltage [V]")
|
||||
self.setLabel("right", "LED [%]")
|
||||
self.getAxis("right").setRange(0, 110) # Adding some margin
|
||||
self.showGrid(x=True, y=True)
|
||||
# self.setTitle("Test")
|
||||
# self.setLabel("bottom", "time [s]")
|
||||
# self.setLabel("left", "Voltage [V]")
|
||||
# self.setLabel("right", "LED [%]")
|
||||
# self.getAxis("right").setRange(0, 110) # Adding some margin
|
||||
# self.showGrid(x=True, y=True)
|
||||
self.time = []
|
||||
self.voltage = []
|
||||
self.led = []
|
||||
|
||||
self.vline = self.plot(
|
||||
self.v_line = pg.PlotCurveItem(
|
||||
self.time,
|
||||
self.voltage,
|
||||
pen=pg.mkPen("b", width=2),
|
||||
@ -26,15 +48,24 @@ class Plot(pg.PlotWidget):
|
||||
symbolSize=5,
|
||||
symbolBrush="b",
|
||||
)
|
||||
self.lline = self.plot(
|
||||
self.l_line = pg.PlotCurveItem(
|
||||
self.time,
|
||||
self.led,
|
||||
pen=pg.mkPen("r", width=2)
|
||||
)
|
||||
self.l_box.addItem(self.l_line)
|
||||
self.v_box.addItem(self.v_line)
|
||||
self.update_views()
|
||||
self.v_plot_item.getViewBox().sigResized.connect(self.update_views)
|
||||
|
||||
def update(self, time, voltage, led):
|
||||
def update_views(self):
|
||||
self.l_box.setGeometry(self.v_plot_item.getViewBox().sceneBoundingRect())
|
||||
self.l_box.linkedViewChanged(self.v_plot_item.getViewBox(), self.l_box.XAxis)
|
||||
|
||||
|
||||
def update_plot(self, time, voltage, led):
|
||||
self.time.append(time)
|
||||
self.voltage.append(voltage)
|
||||
self.led.append(led)
|
||||
self.vline.setData(self.time, self.voltage)
|
||||
self.lline.setData(self.time, self.led)
|
||||
self.v_line.setData(self.time, self.voltage)
|
||||
self.l_line.setData(self.time, self.led)
|
||||
|
Loading…
x
Reference in New Issue
Block a user