熊猫/ matplotlib线图不显示x轴文本标签

时间:2019-03-08 14:47:26

标签: python pandas matplotlib

问题

将数据从DataFrame绘制到折线图中将x轴上的“日期”排除在外。

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
north_result_df.plot.line()

enter image description here

折线图要求日期在x轴的“月”正上方。日期显示它们是否为数字而不是字符串...任何帮助将不胜感激!如您所知,我对Pandas刚起步...

解决方案

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df.index, north_result_df["total"])
plt.show()

1 个答案:

答案 0 :(得分:2)

您可以使用pyplot

import matplotlib.pyplot as plt
north_result =[5,6,7,2,8,5,4,8,9,4,1,5]
dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df)
plt.show()

结果将是:

enter image description here