小编Mic*_*ael的帖子

Python pyqtgraph如何在图上设置x和y轴限制,没有自动量程

我想知道如何设置为pyqtgraph.GraphicsWindow.addPlot对象显示的x和y轴限制.我需要在循环中显示大量数据(因此使用pyqtgraph)但我宁愿预先分配我的轴而不是允许自动量程可能提高速度.举个例子,

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="My plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')
p1 = win.addPlot(title="plot1")
p2 = win.addPlot(title="plot2")
curve1 = p1.plot(pen='y')
curve2 = p1.plot(pen='r')
curve3 = p2.plot(pen='b')
x = np.linspace(0,10,1000)
x_current = x[0]
p1.setXRange((5,20), padding=0)
for i in range(1,len(x)):
    x_current = np.append(x_current,x[i])
    curve1.setData(x_current,np.sin(x_current))
    curve2.setData(x_current,np.cos(x_current))
    curve3.setData(x_current,np.tan(x_current))
    app.processEvents()

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
Run Code Online (Sandbox Code Playgroud)

问题在于线p1.setXRange((5,20),padding=0).这会导致错误:TypeError:setXRange()至少需要3个参数(给定3个)

我认为这应该是一个非常简单的问题,只需在绘图前设置轴范围.

python plot axis graph pyqtgraph

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

axis ×1

graph ×1

plot ×1

pyqtgraph ×1

python ×1