【问题标题】:None values in pyqtgraphpyqtgraph中的无值
【发布时间】:2016-03-21 05:42:41
【问题描述】:

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

pyqtgraph - yellow circle has null values

graph using excel

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

【问题讨论】:

    标签: python excel pandas pyqtgraph


    【解决方案1】:

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

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

    从文档中引用 connect 关键字:

    默认为all,表示全连接。 pairs 仅导致 要绘制的偶数段。 finite 导致细分为 如果它们附加到 nan 或 inf 值,则省略。对于任何其他 连接,指定一个布尔值数组。


    这是一个例子

    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_()
    

    【讨论】:

    • 新版本好像connect不工作了
    猜你喜欢
    • 2017-04-12
    • 2016-10-27
    • 2014-05-17
    • 2014-07-07
    • 2013-08-14
    • 2020-12-16
    • 2020-04-10
    • 2021-06-18
    • 2022-07-11
    相关资源
    最近更新 更多