【问题标题】:Inverting the Y axis in PyQtGraph在 PyQtGraph 中反转 Y 轴
【发布时间】:2017-07-30 09:40:43
【问题描述】:

我正在使用 Python 和 PyQt4 开发一个应用程序,它根据深度绘制不同的参数。绘图包是 PyQtGraph,因为它具有良好的动画速度特性。由于我正在针对深度进行绘图,因此我想反转 Y 轴。我发现我可以modify the ViewBox class in the PyQtGraph's documentation。所以我从我的 Python Site Packages 文件夹中修改了类的代码。但我希望能够从我的应用程序代码中修改类,而不必修改 PyQtGraph 的代码 (invertY=True)。原因是我想要一些带有倒 Y 轴的 PlotWidgets,而其中一些没有。有什么办法可以做到这一点,例如在下面的代码中?我一直无法通过代码中的getting the ViewBox 做到这一点:

import sys
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import random
import time

app = QtGui.QApplication([])
p = pg.plot()
curve = p.plot()

##initialize the arrays
data = []
data.append(random.random())
n = []
n.append(time.clock())

##define the plotting function
def update():

    data.append(data[-1] + 0.2 * (0.5 - random.random()))
    n.append(time.clock())
    curve.setData(data,n)
    time.sleep(0.1)

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)

if __name__ == '__main__':

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

【问题讨论】:

    标签: python qt pyqt pyqtgraph


    【解决方案1】:

    在您的情况下,curvePlotDataItem。要获取PlotDataItem 的视图框,请使用其getViewBox() 方法。然后视图框有一个invertY 方法。

    p = pg.plot()
    curve = p.plot()
    curve.getViewBox().invertY(True)
    

    【讨论】:

      猜你喜欢
      • 2022-08-03
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      相关资源
      最近更新 更多