Python pyqtgraph如何在图形上设置x和y轴限制,没有自动调整范围 [英] Python pyqtgraph how to set x and y axis limits on graph, no autorange

查看:2817
本文介绍了Python pyqtgraph如何在图形上设置x和y轴限制,没有自动调整范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何设置为pyqtgraph.GraphicsWindow.addPlot对象显示的x和y轴限制.我需要在循环中显示很多数据(因此使用pyqtgraph),但我宁愿预分配轴,而不是允许自动调整范围以潜在地提高速度.例如,

I would like to know how I can set the x and y axis limits that are displayed for a pyqtgraph.GraphicsWindow.addPlot object. I need to display a lot of data inside a loop (hence using pyqtgraph) but I would rather preallocate my axes as opposed to allowing autorange to potentially enhance speed. As an example,

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()至少接受3个参数(给定3个参数)

The problem lies in the line p1.setXRange((5,20),padding=0). This results in the error: TypeError: setXRange() takes at least 3 arguments (3 given)

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

I think this should be a very simple question, just setting the axis ranges before plotting.

推荐答案

如错误消息所示,您没有为setXRange()提供正确数量的参数.正确的行应如下所示:

As the error message indicates, you have not supplied the correct number of arguments to setXRange(). The correct line should look like:

p1.setXRange(5, 20, padding=0)

此处的文档: http://www.pyqtgraph.org/documentation/graphicsItems/viewbox .html#pyqtgraph.ViewBox.setXRange

这篇关于Python pyqtgraph如何在图形上设置x和y轴限制,没有自动调整范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆