Python matplotlib以日期為x軸作圖代碼實(shí)例
這篇文章主要介紹了Python matplotlib以日期為x軸作圖代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
效果圖如下

代碼如下
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 #用來正常顯示負(fù)號
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',
'藍(lán)思科技':'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='藍(lán)思科技')
if (count == 6):
plt.plot(rili[::-1], data, label='歌爾股份')
plt.legend()
plt.show()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python+selenium實(shí)現(xiàn)QQ郵箱自動(dòng)發(fā)送功能
這篇文章主要為大家詳細(xì)介紹了python+selenium實(shí)現(xiàn)QQ郵箱自動(dòng)發(fā)送功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01
Python編程使用PyQt5庫實(shí)現(xiàn)動(dòng)態(tài)水波進(jìn)度條示例
這篇文章主要介紹了Python編程使用PyQt5庫實(shí)現(xiàn)動(dòng)態(tài)水波進(jìn)度條的示例代碼解析,有需要的朋友可以借鑒參考下希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2021-10-10
Python實(shí)現(xiàn)Windows和Linux之間互相傳輸文件(文件夾)的方法
下面小編就為大家?guī)硪黄狿ython實(shí)現(xiàn)Windows和Linux之間互相傳輸文件(文件夾)的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05
Python3操作Excel文件(讀寫)的簡單實(shí)例
這篇文章主要給大家介紹了關(guān)于Python3操作Excel文件(讀寫)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Python3具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
jupyter notebook更換皮膚主題的實(shí)現(xiàn)
這篇文章主要介紹了jupyter notebook更換皮膚主題的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01

