您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章将为大家详细讲解有关Python中matplotlib以日期为x轴作图的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
效果图如下
代码如下
from datetime import datetime, date, timedelta import matplotlib.pyplot as plt import tushare as ts plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 def get_riqi(): count = 30 i = 0 today = date.today() #今天日期 riqi_list=[] riqi_list.append(str(today)) while(i<=count): i+=1 riqi_list.append(str((today + timedelta(days=-i)))) return riqi_list def count(Data): data_list = [] sum_list = [] for data in Data: sum = 0 list = [] for jiage in data: sum+=jiage list.append(jiage) sum_list.append(round(sum,2)) data_list.append(list) return sum_list,data_list def get_juedui(Data): sum = 0 data = [] for i in Data[::-1]: sum += i data.append(sum) return data technology = { '海康威视':'002415', '中兴通讯':'000063', '科大讯飞':'002230', '立讯精密':'002475', '蓝思科技':'300433', '歌尔股份':'002241' } store = [technology] technology = [] def get_data(store,riqi_list): count = 0 for Stock_pool in store: count +=1 for stock in Stock_pool.values(): data = ts.get_hist_data(stock,start=riqi_list[-1]) if (count == 1): technology.append(data.loc[:, 'p_change']) riqi_list = get_riqi() get_data(store,riqi_list) riqi_list = technology[0].index rili = [] for riqi in riqi_list: rili.append(riqi[5:]) sum2,data2 = count(technology) riqi_list = [datetime.strptime(d, '%m-%d').date() for d in rili] count = 0 for i in data2: count+=1 data = get_juedui(i) if(count==1): plt.plot(rili[::-1], data,label = '海康威视' ) if(count==2): plt.plot(rili[::-1], data,label = '中兴通讯' ) if(count==3): plt.plot(rili[::-1], data,label = '科大讯飞' ) if(count==4): plt.plot(rili[::-1], data,label = '立讯精密' ) if (count == 5): plt.plot(rili[::-1], data, label='蓝思科技') if (count == 6): plt.plot(rili[::-1], data, label='歌尔股份') plt.legend() plt.show()
关于“Python中matplotlib以日期为x轴作图的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。