python_pyqtgraph常用语法记录

PyQtGraph是一个用于数据可视化的Python库,提供多种图形控件如PlotDataItem、PlotItem和ImageItem。全局设置包括鼠标行为配置、颜色和画笔选项。辅助函数涉及数据显示、颜色处理等。PlotDataItem是用于绘制曲线和散点图的核心类,支持数据变换和抽取。
摘要由CSDN通过智能技术生成

目录

全局设置 setConfigOptions()

PyQtGraph的辅助函数

 数据显示函数 Simple Data Display Functions

颜色、画笔和笔刷 Color,Pen,and Brush Functions

Data Slicing 暂用不上

Coordinate Transformation 暂用不上

SI Unit Conversion Functions 暂用不上

Image Preparation Function 暂用不上

Mesh Generation Functions 暂用不上

Miscellaneous Functions 暂用不上

Legacy Color Helper Functions 暂用不上

pyqtgraph的图形控件 PyQtGraph's Graphic Items

PlotDataItem

PlotItem

ImageItem

 ViewBox

GraphicsLayout

GrahpicsWidget 

GraphicsItem

 GraphicsScene


全局设置 setConfigOptions()

Global Configuration Options — pyqtgraph 0.13.3 documentation

数据类型默认值取值说明
leftButtonPanboolTrue

If True, dragging the left mouse button over a ViewBox causes the view to be panned. If False, then dragging the left mouse button draws a rectangle that the ViewBox will zoom to.

【True:鼠标左键拖拽图形,整个图形拽着一起移动;False:鼠标左键绘制一个矩形区域,ViewBox将放大这个矩形区域的内容】

foreground

See

mkColor()

'd'

Default foreground color for text, lines, axes, etc.

【文本、线条、坐标轴等前景色】

background

See

mkColor()

'k'

Default background for GraphicsView.

【GraphicView的背景色】

antialiasboolFalse

Enabling antialiasing causes lines to be drawn with smooth edges at the cost of reduced performance.

【启用抗锯齿使线条平滑,但会降低性能,默认不启用】

imageAxisOrderstr'col-major'

For ‘row-major’, image data is expected in the standard row-major (row, col) order. For ‘col-major’, image data is expected in reversed column-major (col, row) order. The default is ‘col-major’ for backward compatibility, but this may change in the future.

【图形排列顺序规则,row-major 以行为主,也就是先把行填充完再整下一行;col-major以列为主,一列填充万再下一列。注:个人理解,没用过,取默认值】

editorCommandstr or NoneNone

Command used to invoke code editor from ConsoleWidget.

【用于从ConsoleWidget调用代码编辑器的命令。注:个人理解,没用过,取默认值】

exitCleanupboolTrue

Attempt to work around some exit crash bugs in PyQt and PySide.

【PyQt或PySide出现bug崩溃时,尝试解决】

useOpenGLboolFalse

Enable OpenGL in GraphicsView.

【是否在GraphicsView中调用OpenGL,默认不调用】

useCupyboolFalse

Use cupy to perform calculations on the GPU. Only currently applies to ImageItem and its associated functions.

【使用cupy在GPU上执行计算。当前仅适用于ImageItem及其关联函数】

useNumbaboolFalse

Use numba acceleration where implemented.

【在实施时使用numba加速。】

enableExperimentalboolFalse

Enable experimental features (the curious can search for this key in the code). In combination with useOpenGL, this makes PlotCurveItem use PyOpenGL for curve drawing.

【启用实验功能(好奇的人可以在代码中搜索这个键)。结合使用OpenGL,这使得PlotCurveItem使用PyOpenGL绘制曲线。】

crashWarningboolFalseIf True, print warnings about situations that may result in a crash.
segmentedLineModestr'auto'

For ‘on’, lines are always plotted in segments. For ‘off’, lines are never plotted in segments. For ‘auto’, whether lines are plotted in segments is automatically decided based on pen poperties and whether anti-aliasing is enabled.

【开启的话,线条总是以线段的形式绘制。关闭的话,就总是绘制直线,不会绘制线段。‘auto’,根据笔的弹出度以及是否启用了抗锯齿来自动决定是否以线段的形式绘制线】

PyQtGraph的辅助函数

PyQtGraph’s Helper Functions — pyqtgraph 0.13.3 documentation

 数据显示函数 Simple Data Display Functions

pyqtgraph.plot(*args,**kargs)

创建并返回 PlotWidget 接收 title 参数作为窗体标题,其他参数参看 PlotItem.plot()

pyqtgraph.image(*args,**kargs)

创建并返回 ImageView ,该控件用于显示2D或3D的图片数据。接收 title 参数作为窗体标题,其他参数参看 ImageView.setImage()

pyqtgraph.dbg(*args,**kargs)

创建一个控制台窗口并开始监视异常。

颜色、画笔和笔刷 Color,Pen,and Brush Functions

Qt设计了QColor QPen QBrush用来绘制和填充颜色,有时候用起来不是很方便。PyQtGraph提供mkColor(),mkPen(),mkBrush()来实现这些功能,很多时候颜色、画笔、笔刷已经作为参数内嵌在控件中,使用过程中只要设置参数就可以。

例如:

pg.plot(xdata,ydata,pen='r')

pg.plot(xdata,ydata,pen=pg.mkPen('r'))

pg.plot(xdata,ydata,pen=QPen(QColor(255,0,0)))

pyqtgraph.mkColor(*args)

参数类型

‘c’r,g,b,c,m,y,k,w
R,G,B,[A]0-255的整数
(R,G,B,[A])0-255的整数
float灰度,0.0-1.0
intsee intColor()
(int,hues)see intColor()
"#RGB"
'#RGBA"
"#RRGGBB"
"#RRGGBBAA"
QColorQColor实例

pyqtgraph.mkPen(*args,**kargs)

例如

mkPen(color)

mkPen(color,width=2)

mkPen(cosmetic=False,width=4.5,color='r')

mkPen({'color':'#FF0',width:2})

mkPen(None) # (no pen)

pyqtgraph.mkBrush(*args,**kwds)

默认构建的都是实体填充的笔刷,接受mkColor()的颜色参数。

mkBrush(None)返回一个不可见的笔刷

pyqtgraph.hsvColor(hue,sat=1.0,val=1.0,alpha=1.0)

HSVa的值设置的颜色(参数都是0.0-1.0) 

pyqtgraph.intColor(index,hues=9,values=1,maxValue=255,minValue=150,maxHue=360,minHue=0,sat=255,alpha=255)

通过一个简单的索引值创建颜色。程序内部预设了一个颜色列表。

。。。【平时用不上的就不写了,想看的小伙伴自行前往官网】

Data Slicing 暂用不上

用不上,以后有用上再行补充

Coordinate Transformation 暂用不上

用不上,以后有用上再行补充

SI Unit Conversion Functions 暂用不上

Image Preparation Function 暂用不上

Mesh Generation Functions 暂用不上

Miscellaneous Functions 暂用不上

Legacy Color Helper Functions 暂用不上

pyqtgraph的图形控件 PyQtGraph's Graphic Items

Since pyqtgraph relies on Qt’s GraphicsView framework, most of its graphics functionality is implemented as QGraphicsItem subclasses. This has two important consequences: 1) virtually anything you want to draw can be easily accomplished using the functionality provided by Qt. 2) Many of pyqtgraph’s GraphicsItem classes can be used in any normal QGraphicsScene.

【由于pyqtgraph依赖Qt的GraphicsView框架,因此它的大部分图形功能都是作为QGraphicsItem子类实现的。基于以上有以下两点好处:

1)使用Qt提供的功能,几乎可以轻松地完成想要绘制的内容。

2)pyqtgraph的许多GraphicsItem类可以在任何普通的QGraphicsScene中使用】

PlotDataItem

PlotDataItem — pyqtgraph 0.13.3 documentation

class pyqtgrap.PlotDataItem(*args,**kargs)

基类:GraphicsObject

PlotDataItem provides a unified interface for displaying plot curves, scatter plots, or both. It also contains methods to transform or decimate the original data before it is displayed 

【PlotDataItem提供了用于显示绘制曲线、散点图或者两者的统一界面。它还包含在显示原始数据之前对其进行转换或抽取的方法。】

pyqtgraph.plot()和PlotItem.plot()创建的都是PlotDataItem的实例。

如果很明确就是要创建折线或散点图,可以使用PlotCurveItem或ScatterPlotItem

信号:

sigPlotChanged(self)控件中数据更新触发该信号
sigClicked(self,ev)点击控件,触发
sigPointsClicked(self,points,ev)图形中的点被点击,将返回当前鼠标所在位置的点列表
sigPointsHovered(self,points,ev)鼠标悬浮在某一个点上,将返回当前鼠标所在位置的点列表

创建方法:

PlotDataItem(x,y)

x,y:array_like coordination values  列表

PlotDataItem(y)只有y轴数据,x会自动生成序列
PlotDataItem(x=x,y=y)
PlotDataItem(ndarray(N,2))
PlotDataItem(recarray)numpy record array with dtype=[('x',float),('y',float),...]
PlotDataItem(list-of-dicts)[{'x':x,'y':..},...]
PlotDataItem(dict-of-lists){'x':[....],'y':[...],...}

线条样式设置:

connect 值说明

‘all’:连接所有的点

'pairs':只与相邻的点相连

'finite': 如果数据列表中有为空的数据,线条在对应位置断开不画线

PlotItem

PlotItem — pyqtgraph 0.13.3 documentation

class pyqtgraph.PlotItem

基类:GraphicsWidget

这个类相当于是 ViewBox + axes。 

主要功能:

1 管理ViewBox、AxisItems 和 LabelItems的位置

2 创建和管理一系列的PlotDataItems在ViewBox里显示

3 使用常用的显示和分析选项实现上下文菜单

ImageItem

 ImageItem — pyqtgraph 0.13.3 documentation

 ViewBox

ViewBox — pyqtgraph 0.13.3 documentation

基类:GraphicsWidget 

GraphicsLayout

GraphicsLayout — pyqtgraph 0.13.3 documentation

GrahpicsWidget 

GraphicsWidget — pyqtgraph 0.13.3 documentation

基类:GraphicsItem 

GraphicsItem

GraphicsItem — pyqtgraph 0.13.3 documentation

基类:object

 GraphicsScene

GraphicsScene — pyqtgraph 0.13.3 documentation

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值