【问题标题】:PyQtGraph: last element is not plotted out when setClipToView set to TruePyQtGraph:当 setClipToView 设置为 True 时,未绘制最后一个元素
【发布时间】:2015-07-02 17:02:22
【问题描述】:

为了减少绘制 gui 更新的时间,我设置了 setClipToView(True),以节省 CPU 时间来绘制图表中不必要的(看不见的)部分。我的代码如下。

import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
from PySide.QtCore import QTime
import sys
import numpy as np
import time
from collections import deque

app = QtGui.QApplication([])
grams = deque()
penColor = pg.mkPen(color=(0,0,0),width=2)

pg.setConfigOption('background','w')
pg.setConfigOption('foreground','k')
pg.setConfigOptions(antialias=True)
view = pg.GraphicsView()
outerLayout = pg.GraphicsLayout()
outerLayout.layout.setSpacing(0)
view.setCentralItem(outerLayout)
view.show()
l2 = outerLayout.addLayout()

lowerGraph = l2.addPlot(name = "lower")
lowerGraph.showGrid(x=True,y=True)
lowerGraph.setClipToView(True)
lowerCurve = lowerGraph.plot(pen = penColor)

def update(grams):
    x = [item['x'] for item in grams]
    yLower = [item['y'] for item in grams]
    lowerGraph.setXRange(0,x[-1]+20)
    lowerCurve.setData(x=x, y=yLower)
    QtGui.QApplication.processEvents()
i = 0
j = 0.0
while i < 4:
    gram = np.random.uniform(0,51,size=1)
    grams.append({'x':j,'y':gram[0]})
    update(grams)
    i += 1
    j += 1000
    time.sleep(0.1)

lowerCurve.clear()
x = [item['x'] for item in grams]
y = [item['y'] for item in grams]
lowerGraph.setXRange(0,x[-1]+20)
lowerCurve = lowerGraph.plot(x=x,y=y,pen = penColor)

QtGui.QApplication.instance().exec_()

当我注释掉 setToCliptoView(True) 数据的最后一个元素时,数据的最后一个元素也被绘制出来,但其他方式将其从绘制中丢弃。

我猜这是一个错误。 感谢您的时间。 问候, 乌波尔

【问题讨论】:

    标签: python pyqtgraph


    【解决方案1】:

    这是 PlotDataItem 的 getData 函数中的一个错误,当您动态更新剪辑数据时会显示该错误:https://groups.google.com/forum/#!topic/pyqtgraph/p1UE-zvSI2g

    在最新的开发分支中,将 PlotDataItem.py 的第 564 行从

    x1 = np.clip(int((range.right()-x[0])/dx)+2*ds , 0, len(x)-1)
    

    x1 = np.clip(int((range.right()-x[0])/dx)+2*ds , 0, len(x))
    

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 2015-07-16
      • 2016-07-26
      • 2015-05-03
      • 2016-06-13
      • 2018-07-13
      相关资源
      最近更新 更多