【问题标题】:Data Coverage Plot using matplotlib and Pandas DataFrame使用 matplotlib 和 Pandas DataFrame 的数据覆盖图
【发布时间】:2018-02-06 17:49:14
【问题描述】:

我已经在 pandas 数据框中创建了时间序列的数据覆盖率,并希望在 Matplotlib 或 PyQtGraph 中绘制数据覆盖率。

数据框

DateTime    WD98    WS120   WS125B  WD123   WS125A
31-07-2013  100 99.9    99.9    NaN NaN
31-08-2013  100 100 100 NaN NaN
30-09-2013  100 100 100 NaN NaN
31-10-2013  100 100 100 NaN NaN
30-11-2013  100 100 100 100 100
31-12-2013  100 100 100 100 100
31-01-2014  100 100 100 100 100
28-02-2014  100 100 100 100 100
31-03-2014  100 100 100 100 100
30-04-2014  100 100 100 100 100
31-05-2014  67.1    100 100 67.1    7.7
30-06-2014  NaN NaN 100 0   69.2
31-07-2014  NaN NaN 100 0   100
31-08-2014  NaN NaN 100 0   96.2

我想以下面的方式绘制(断条图)

上图是使用 Excel 条件格式完成的。请帮帮我。

DataCoverage >= 90 (Green)
DataCoverage >= 75 and DataCoverage < 90 (Yellow)
DataCoverage < 75 (red)

【问题讨论】:

    标签: python pandas matplotlib dataframe pyqtgraph


    【解决方案1】:

    你可以使用seaborn.heatmap:

    import seaborn as sns
    
    df = df.set_index(df.pop('DateTime').dt.strftime('%d-%m-%Y'))
    g = sns.heatmap(df, cmap=['r','y','g'], annot=True, fmt='.0f')
    g.set_yticklabels(g.get_yticklabels(), rotation=0, fontsize=8)
    

    结果:

    更新:更正版本:

    x = df.set_index(df['DateTime'].dt.strftime('%d-%m-%Y')).drop('DateTime', 1)    
    z = pd.cut(x.stack(), bins=[-np.inf, 75, 90, np.inf], labels=[1.,2.,3.]).unstack().apply(pd.to_numeric)    
    g = sns.heatmap(z, cmap=['r','y','g'], fmt='.0f', cbar=False)    
    g.set_yticklabels(g.get_yticklabels(), rotation = 0, fontsize = 8)
    

    结果:

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 1970-01-01
      • 2015-10-30
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2020-08-06
      • 1970-01-01
      相关资源
      最近更新 更多