[英]Pandas/matplotlib line plot does not show x axis text labels
Issue问题
Plotting data from a DataFrame into a line plot excludes "dates" on the x axis.将 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()
Line plot requires dates just above 'months' on the x axis.线图需要 x 轴上“月”正上方的日期。 Dates show if they are numeric and not strings...any help would be greatly appreciated!日期显示它们是否是数字而不是字符串......任何帮助将不胜感激! As you can tell i am pretty new to Pandas...正如你所知道的,我对 Pandas 还很陌生......
Solution解决方案
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()
you can use pyplot你可以使用 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()
the result will be like:结果将是这样的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.