打开QT Designer,新建主窗口并设计界面。在“Display Widgets”中拖动“Graphics View”至主窗口。将控件类提升为“PlotWidget”,头文件选择“pyqtgraph”。保存设计文件,生成.ui文件。将.ui文件加载到Python程序中:编写代码,利用相关库加载.ui文件并显示界面。绘图操作:注册P
在“头文件”这一栏填写“pyqtgraph”也就是你将要导入的库名称,之所以要进行提升是因为QT Designer不包含这个外部的绘画库,但我要使用他,所以需要将此控件的类名替换成pyqtgraph库中的PlotWidget类,以便于后续可以调用,填写之后的图片如下所示
3.1、使用 QT Designer 设计绘图界面 打开 QT Designer,新建主窗口,按步骤 1 和 2 设计界面,保存。在“Display Widgets”中拖动“Graphics View”至主窗口。提升控件类为“PlotWidget”,选择“pyqtgraph”作为头文件。保存设计文件,生成 .ui 文件。3.2、将 .ui 文件加载到 Python 程序中 编写代...
class GraphWidget(QWidget): def __init__(self, parent=None): super(GraphWidget, self).__init__(parent) # 创建一个布局管理器 layout = QVBoxLayout(self) # 创建一个pyqtgraph的绘图部件 self.plot_widget = pg.PlotWidget() # 将绘图部件添加到布局管理器中 layout.addWidget(self.plot_widget)...
import sys from PyQt5 import QtWidgets import pyqtgraph as pg import numpy as np class PlotWindow(QtWidgets.QWidget): def __init__(self): super().__init__() self.plot_widget = pg.PlotWidget() self.plot_item = self.plot_widget.plotItem self.plot_item.setMouseEnabled(x=True, y=True...
可以通过调用.setBackground来改变背景颜色。PlotWidget实例(在 self.graphWidget)。下面的代码将通过传入字符串“w”将背景设置为白色。self.graphWidget.setBackground('w')可以随时设置(和更新)绘图的背景颜色。from PyQt5 import QtWidgets from pyqtgraph import PlotWidget, plot import pyqtgraph as pg import ...
PyQtGraph 中 绘图控件类 有两种 PlotWidget 和 GraphicsLayoutWidget, 都是 GraphicsView 子类。GraphicsView 是 Qt 的 QGraphicsView 子类,在其基础上改进了一些功能。PlotWidget 只能内置一个 绘图对象PlotItem, 而 GraphicsLayoutWidget 可以内置多个 绘图对象。 通常我们使用最多的是PlotWidgetPlotWidget对象的 内置...
如果使用新的数据再次绘图,可以先调用clear方法清除原来的内容(plotitem),如下 + View Code PlotWidget 和 GraphicsLayoutWidget PyQtGraph 中 绘图控件类 有两种 PlotWidget 和 GraphicsLayoutWidget, 都是GraphicsView子类。GraphicsView 是 Qt 的 QGraphicsView 子类,在其基础上改进了一些功能。
self.plot=pg.PlotWidget(enableAutoRange=True)self.ui.verticalLayout.addWidget(self.plot)self.curve=self.plot.plot() 这样呢,我们就把一个画图的对象绑定到了verticalLayout上了。 3: 我们要画东西的时候呢,直接传参数就可以了,一般传pandas的series或者np的array都可以、 ...
# 创建绘制窗⼝类 PlotWindow 对象,内置⼀个绘图控件类 PlotWidget 对象 pw = pg.plot()# 设置图表标题、颜⾊、字体⼤⼩ pw.setTitle("⽓温趋势",color='008080',size='12pt')# 背景⾊改为⽩⾊ pw.setBackground('w')# 显⽰表格线 pw.showGrid(x=True, y=True)# 设置上下左右的...