画图matplotlib

利用matplotlib和日期进行画图: 首先一般数据中日期是str格式,首先进行转换为日期格式

##取出1000011的fildate数据,即日期数据
x=data.loc[1000011,'fildate'].valu
es
##将日期格式转为datetime格式
x = pd.to_datetime(x)
y=data.loc[1000011,'realamt'].values

fig = plt.figure(figsize = (12,6))
ax = fig.add_subplot(1,1,1)
#指定X轴的以日期格式显示
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
#X轴的间隔为周,日:DayLocator,月:MonthLocator
ax.xaxis.set_major_locator(mdates.WeekdayLocator())

plt.plot(x,y)
plt.xlabel("fildate")
plt.ylabel("realamt")
plt.title("每日销售额") #标题
plt.xticks(rotation=45)#将x轴坐标文字旋转45度
plt.show()  #显示图

 

参考价值大的博客:https://blog.csdn.net/helunqu2017/article/details/78736686

猜你喜欢

转载自blog.csdn.net/nowfuture/article/details/83894714
今日推荐