• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python matplotlib以日期为x轴作图代码实例

python 搞代码 4年前 (2022-01-07) 14次浏览 已收录 0个评论

这篇文章主要介绍了Python matplotlib以日期为x轴作图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

这篇文章主要介绍了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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网

以上就是Python matplotlib以日期为x轴作图代码实例的详细内容,更多请关注gaodaima搞代码网其它相关文来源gao@daima#com搞(%代@#码@网章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python matplotlib以日期为x轴作图代码实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址