python - Pandas dataframe.plot() - 折线图 - 未为前两个索引绘制的系列值

标签 python pandas matplotlib

在附加图像(附加数据框和绘制的折线图快照)中 - 系列索引范围从 242.0 到 252.0,但缺少索引 242.0 和 243.0 的数据。 这里有什么问题?

相关代码如下:

import re
import json as js
import matplotlib.pyplot as plt
import pandas as pd

def plot(collector, run_type, stat_type):
       ax = plt.gca()
       run_info = collector.series[run_type]['info']
       dfs = []
       ctr_str = 'Type {}'
       ctr = 0
       for var in run_info:
           ctr += 1
           if not re.search(stat_type, var):
               continue
           var_info = run_info[var]
           try:
               dfs.append(pd.DataFrame({var: var_info['data']}, index=var_info['runs']))
           except:
               print(var_info['data'])
               print(var_info['runs'])
               x=1
       pd.concat(dfs, axis=1, sort=False).sort_index().plot(kind='line', ax=ax)
       plt.show(block=True)

enter image description here

最佳答案

对于 243,值出现在整列(Type1、Type2 和 Type5)中只有一个值的那些列中,因此线图不会绘制这些线。对于 242,nan 似乎打破了该列的行。但是,您需要在绘图之前处理 Nan。

关于python - Pandas dataframe.plot() - 折线图 - 未为前两个索引绘制的系列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57428881/

相关文章:

python - 添加两个具有不同索引的 pandas Series 对象的惯用方法

python - Python代码中的 "In [X]:"和 "Out[Y]:"是什么意思?

python - 从通过 pandas 创建的 html 表中删除边框

matplotlib - Matplotlib,如何在数据坐标之外的图形外部编写注释?

python - 在 matplotlib colorbar 中对齐刻度标签

python - Django 或类似的复合主键

python - 如何使用 TfIdfVectorizer 查找重要单词?

matplotlib - 如何删除 matplotlib 子图中的填充/边框

python - 如何在DataFrame中找到相同的行——python

python - 在 Pandas 中动态命名 DataFrame