首页 > 解决方案 > Labels not getting printed in line charts

问题描述

enter image description hereI have a pandas dataframe in this format:

            Act               Pred
 date
2019-11     100               65
2019-12     86                65

When I plot the line graph,

    df.set_index('date',inplace=True)
    ax = df.plot(kind="line")
    ax.savefig("graph1.png"

I don't get the dates in x axis. It's just 2 lines in the line graph. I don't see the dates "2019-11" and "2019-12" in the x-axis.

Am I missing any parameter for it?

enter image description here

标签: pythonpandasmatplotlib

解决方案


我相信它的字段类型没有正确发布。我将其转换为日期字段并能够获得 X 轴标记。 df["date"] = df["date"].astype('datetime64[ns]')


推荐阅读