pyqtgraph中没有值

2024-04-23 19:57:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用pyqtgraph从包含空值(来自pandas的数据)的数据生成一个图。在

pyqtgraph - yellow circle has null values

graph using excel

我希望使用pyqtgraph的图形与excel图形相同。换言之,区域中不会有具有空值的行。在


Tags: 数据图形区域pandasexcelnullgraphpyqtgraph
1条回答
网友
1楼 · 发布于 2024-04-23 19:57:31

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

Set dataplotcurveitem/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_()

Finite plot

相关问题 更多 >