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 = {
'海康威视':'',
'中兴通讯':'',
'科大讯飞':'',
'立讯精密':'',
'蓝思科技':'',
'歌尔股份':''
}
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轴作图的更多相关文章

  1. Python - matplotlib 数据可视化

    在许多实际问题中,经常要对给出的数据进行可视化,便于观察. 今天专门针对Python中的数据可视化模块--matplotlib这块内容系统的整理,方便查找使用. 本文来自于对<利用python进 ...

  2. Python时间戳和日期的相互转换

    Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼   分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...

  3. python matplotlib 中文显示参数设置

    python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...

  4. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  5. python matplotlib plot 数据中的中文无法正常显示的解决办法

    转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...

  6. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  7. python matplotlib画图产生的Type 3 fonts字体没有嵌入问题

    ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...

  8. Python时间和日期学习

    #coding=utf-8 __author__ = 'Administrator' #日期和时间模块学习 """ Python程序能用很多方式处理日期和时间,转换日期格 ...

  9. Python学习--15 日期和时间

    获取当前时间 # coding: utf-8 from datetime import datetime now = datetime.now() print(now) print(now.strft ...

随机推荐

  1. Python基础之内置函数(二)

    先上一张图,python中内置函数: python官方解释在这:点我点我 继续聊内置函数: callable(object):检查对象是否可被调用,或是否可执行,结果为bool值 def f1(): ...

  2. notepad++(NPP)更换主题颜色

    NPP主题网站:https://lonewolfonline.net/notepad-colour-schemes/ 笔者下载了Nord Notepad++ Theme 然后打开%AppData%\N ...

  3. LeetCode_28. Implement strStr()

    28. Implement strStr() Easy Implement strStr(). Return the index of the first occurrence of needle i ...

  4. tp5.1 where 时间查询

    $where_time = []; if ($_GET['s_time'] && !isset($_GET['e_time'])){ $where_time = ['add_time' ...

  5. 【ARTS】01_34_左耳听风-201900701~201900707

    ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...

  6. conda换源

    装完Anaconda后,建议更新所有的包,因为以后使用很可能会报错. 而更新的时候conda的官方源在美国,不换源就非常蓝瘦,有生之年够呛了. 换源: conda config --add chann ...

  7. python获取昨日日期

    获取昨日日期oneday = datetime.timedelta(days=1) 一天 day = datetime.datetime.strptime(self.date,'%Y-%m-%d') ...

  8. Egret入门学习日记 --- 第十二篇(书中 5.1节 内容)

    第十二篇(书中 5.1节 内容) 昨天把 第4章完成了. 今天来看第5章. 接下来是 5.1节 的内容. 总结一下 5.1节 的重点: 1.如何制作一个公用按钮皮肤. 跟着做: 重点1:如何制作一个公 ...

  9. 关于React的脚手架

    Rewire你的应用 https://ant.design/docs/react/use-with-create-react-app-cn create-react-app (官方脚手架 简称cra) ...

  10. SecureCRT 配色方案

    整体效果: 一:Options -- Global Options 1.Normal colors     2.Bold colors 二 :Options -- Session Options 1. ...