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 = {
'海康威视':'',
'中兴通讯':'',
'科大讯飞':'',
'立讯精密':'',
'蓝思科技':'',
'歌尔股份':''
}
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轴作图的更多相关文章
- Python - matplotlib 数据可视化
在许多实际问题中,经常要对给出的数据进行可视化,便于观察. 今天专门针对Python中的数据可视化模块--matplotlib这块内容系统的整理,方便查找使用. 本文来自于对<利用python进 ...
- Python时间戳和日期的相互转换
Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼ 分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- python中时间日期格式化符号
python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...
- python matplotlib plot 数据中的中文无法正常显示的解决办法
转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...
- python datetime 时间日期处理小结
python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- Python时间和日期学习
#coding=utf-8 __author__ = 'Administrator' #日期和时间模块学习 """ Python程序能用很多方式处理日期和时间,转换日期格 ...
- Python学习--15 日期和时间
获取当前时间 # coding: utf-8 from datetime import datetime now = datetime.now() print(now) print(now.strft ...
随机推荐
- CentOS7下搭建SVN服务器
(1).安装SVN 1)安装SVN [root@youxi1 ~]# yum -y install subversion mod_dav_svn [root@youxi1 ~]# cat /etc/s ...
- Java RSA分段加密
我们通过Java进行RSA加密的时候,可能会出现如下问题: /** * 私钥加密 * * @param data 待加密数据 * @param key 密钥 * @return byte[] 加密数据 ...
- (六)Centos之目录作用介绍
我们先切换到系统根目录 / 看看根目录下有哪些目录 这里首先看下 根目录/ 下的 bin 和 sbin: 在user下也有bin和sbin 根目录下的bin和sbin,usr目录下的bin和sbin, ...
- git clone时加上--depth 1
当项目过大时,git clone时会出现error: RPC failed; HTTP curl The requested URL returned error: Gateway Time-out的 ...
- jQuery BlockUI Plugin Demo 2
Overview The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without l ...
- GitLab基本使用
一.引言 在微服务架构中,由于我们对系统的划分粒度足够小,服务会很多,而且也存在经常迭代的情况.如果还按照以前的部署方式显得非常吃力和复杂,并且很容易出现错误.而随着容器技术的发展,这个时候持续集成( ...
- ruby tk实现简易计算器
#encding:GBK require 'tk' module Const WIDTH_OF_PANEL = 370 HEIGHT_OF_PANEL = 520 SIZE_OF_BUTTON_H = ...
- 开始使用 git(配置+常用命令)
▶ 注意 页面显示问题: -- 是两个短横线 - 是一个横短线 由于显示问题导致两个短横线之间没有空格,看起来像是一条横线,实则是两条短横线 ▶ git 常用命令 ◆ git add ● git ad ...
- 第十六章:网络IPC 套接字
一.IP地址和端口 套接字接口可以用于计算机间通信.目前计算机间使用套接字通讯需要保证处于同一网段. 为了查看是否处于同一网段,我们可以使用IP地址判断. IP地址是计算机在网络中的唯一标识.IP地址 ...
- docker 实践二:操作镜像
本篇我们来详细介绍 docker 镜像的操作. 注:环境为 CentOS7,docker 19.03 之前已经说过,容器是 docker 的核心概念之一,所以对应的就需要知道它的使用方法,接下来我们就 ...