None pyqtgraph 中的值

None values in pyqtgraph

我正在尝试使用 pyqtgraph 从包含空值的数据(来自 pandas 的数据)制作图表。

pyqtgraph - yellow circle has null values

graph using excel

我希望使用 pyqtgraph 的图形与 excel 图形相同。换句话说,该区域中没有空值的行。

使用yourcurve.setData(x, y, connect="finite")

Set data in plotcurveitem/plotdataitem has the keyword connect 正是您要查找的内容。

引用有关 connect 关键字的文档:

Default is all, indicating full connection. pairs causes only even-numbered segments to be drawn. finite causes segments to be omitted if they are attached to nan or inf values. For any other connectivity, specify an array of boolean values.


这是一个例子

import numpy as np
import pyqtgraph as pg
from PyQt4 import QtCore

a = np.array([1, 2, 3, np.nan, 5, 6, 7, np.nan, 9, 10, 11])
b = np.array([1, 2, 3, np.nan, 3, 2, 1, np.nan, 1, 2, 3])
c = b+3

w = pg.PlotWindow()
finitecurve = pg.PlotDataItem(a, b, connect="finite", pen=(255, 255, 0))
normalcurve = pg.PlotDataItem(a, c, pen=(255, 0, 0))
w.addItem(normalcurve)
w.addItem(finitecurve)
w.show()

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