【发布时间】:2015-06-18 08:34:22
【问题描述】:
我想知道如何设置为 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_()
问题在于p1.setXRange((5,20),padding=0) 行。这会导致错误:TypeError: setXRange() take at least 3 arguments (3 given)
我认为这应该是一个非常简单的问题,只是在绘图之前设置轴范围。
【问题讨论】:
标签: python graph plot axis pyqtgraph