def data_show(self, data_dict): print('------- 趋势图 ------') date_list = [] sales_list = [] for k, v in data_dict.items(): date_list.append(datetime.strptime(k, '%Y-%m-%d').date()) # datetime.strptime(k, '%Y-%m-%d').date() sales_list.append(v) print(len(date_list), len(sales_list)) print(date_list) x = np.array(date_list) y = np.array(sales_list) plt.figure(figsize=(20, 15)) # 图片大小 font1 = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=20) # 可指定计算机内的任意字体,size为字体大小 plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d')) # 设置坐标轴为时间格式 plt.gca().xaxis.set_major_locator(mdates.DayLocator()) plt.plot(x, y, 'o-', label='咖啡豆销量') # 'o- 线条样式 # plt.gcf().autofmt_xdate() # 自动旋转日期标记 plt.xticks(fontsize=5,rotation=45) # ,rotation=90 设置坐标字体大小,文本旋转角度 plt.savefig('coffee.jpg', dpi=600) # dpi 分辨率 plt.legend(prop=font1, loc="upper right") # 鼠标放在图片上显示 x y 坐标 plt.show()
plt
猜你喜欢
转载自blog.csdn.net/l1159015838/article/details/81216554
今日推荐
周排行