Python金融數(shù)據(jù)可視化匯總
通過(guò)本篇內(nèi)容給大家介紹一下Python實(shí)現(xiàn)金融數(shù)據(jù)可視化中兩列數(shù)據(jù)的提取、分別畫(huà)、雙坐標(biāo)軸、雙圖、兩種不同的圖等代碼寫(xiě)法和思路總結(jié)。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
y = np.random.standard_normal((20,2))
# print(y)
'''
不同的求和
print(y.cumsum())
print(y.sum(axis=0))
print(y.cumsum(axis=0))
'''
# 繪圖
plt.figure(figsize=(7,4))
plt.plot(y.cumsum(axis=0),linewidth=2.5)
plt.plot(y.cumsum(axis=0),'bo')
plt.grid(True)
plt.axis("tight")
plt.xlabel('index')
plt.ylabel('values')
plt.title('a simple plot')
plt.show()

2.下面分別提取兩組數(shù)據(jù),進(jìn)行繪圖。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)
print(y)
# 重點(diǎn)下面兩種情況的區(qū)別
print(y[1]) # 取得是 第1行的數(shù)據(jù) [-0.37003581 1.74900181]
print(y[:,0]) # 取得是 第1列的數(shù)據(jù) [ 1.73673761 -0.37003581 0.21302575 0.35026529 ...
# 繪圖
plt.plot(y[:,0],lw=2.5,label="1st",color='blue')
plt.plot(y[:,1],lw=2.5,label="2st",color='red')
plt.plot(y,'ro')
# 添加細(xì)節(jié)
plt.title("A Simple Plot",size=20,color='red')
plt.xlabel('Index',size=20)
plt.ylabel('Values',size=20)
# plt.axis('tight')
plt.xlim(-1,21)
plt.ylim(np.min(y)-1,np.max(y)+1)
# 添加圖例
plt.legend(loc=0)
plt.show()


3.雙坐標(biāo)軸。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)
y[:,0]=y[:,0]*100
fig,ax1 = plt.subplots()
plt.plot(y[:,0],'b',label="1st")
plt.plot(y[:,0],'ro')
plt.grid(True)
plt.axis('tight')
plt.xlabel("Index")
plt.ylabel('Values of 1st')
plt.title("This is double axis label")
plt.legend(loc=0)
ax2=ax1.twinx()
plt.plot(y[:,1],'g',label="2st")
plt.plot(y[:,1],'r*')
plt.ylabel("Values of 2st")
plt.legend(loc=0)
plt.show()

4. 分為兩個(gè)圖繪畫(huà)。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)
y[:,0]=y[:,0]*100
plt.figure(figsize=(7,5)) # 確定圖片大小
plt.subplot(211) # 確定第一個(gè)圖的位置 (行,列,第幾個(gè))兩行一列第一個(gè)圖
plt.plot(y[:,0],'b',label="1st")
plt.plot(y[:,0],'ro')
plt.grid(True)
plt.axis('tight')
plt.xlabel("Index")
plt.ylabel('Values of 1st')
plt.title("This is double axis label")
plt.legend(loc=0)
plt.subplot(212) # 確定第一個(gè)圖的位置
plt.plot(y[:,1],'g',label="2st")
plt.plot(y[:,1],'r*')
plt.ylabel("Values of 2st")
plt.legend(loc=0)
plt.show()

5.在兩個(gè)圖層中繪制兩種不同的圖(直線圖立方圖)
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)
y[:,0]=y[:,0]*100
plt.figure(figsize=(7,5)) # 確定圖片大小
plt.subplot(121) # 確定第一個(gè)圖的位置
plt.plot(y[:,0],'b',label="1st")
plt.plot(y[:,0],'ro')
plt.grid(True)
plt.axis('tight')
plt.xlabel("Index")
plt.ylabel('Values',size=20)
plt.title("1st date set")
plt.legend(loc=0)
plt.subplot(122) # 確定第一個(gè)圖的位置
plt.bar(np.arange(len(y[:,1])),y[:,1],width = 0.5,color='g',label="2nd") # 直方圖的畫(huà)法
plt.grid(True)
plt.xlabel("Index")
plt.title('2nd date set')
plt.legend(loc=0)
plt.show()

以上就是本次交給大家的Python制作金融數(shù)據(jù)等用到的圖形化界面代碼寫(xiě)法。
- 利用Python繪制MySQL數(shù)據(jù)圖實(shí)現(xiàn)數(shù)據(jù)可視化
- 利用Python代碼實(shí)現(xiàn)數(shù)據(jù)可視化的5種方法詳解
- Python數(shù)據(jù)可視化正態(tài)分布簡(jiǎn)單分析及實(shí)現(xiàn)代碼
- 基于Python數(shù)據(jù)可視化利器Matplotlib,繪圖入門(mén)篇,Pyplot詳解
- 利用Python進(jìn)行數(shù)據(jù)可視化常見(jiàn)的9種方法!超實(shí)用!
- 舉例講解Python的Tornado框架實(shí)現(xiàn)數(shù)據(jù)可視化的教程
- 以911新聞為例演示Python實(shí)現(xiàn)數(shù)據(jù)可視化的教程
- Python實(shí)現(xiàn)數(shù)據(jù)可視化看如何監(jiān)控你的爬蟲(chóng)狀態(tài)【推薦】
- Python數(shù)據(jù)可視化編程通過(guò)Matplotlib創(chuàng)建散點(diǎn)圖代碼示例
- python3對(duì)拉勾數(shù)據(jù)進(jìn)行可視化分析的方法詳解
相關(guān)文章
Python中判斷語(yǔ)句入門(mén)指南(if?elif?else語(yǔ)句)
if elif else語(yǔ)句是Python中的控制語(yǔ)句,用于根據(jù)條件執(zhí)行不同的操作,下面這篇文章主要給大家介紹了關(guān)于Python中判斷語(yǔ)句入門(mén)指南(if?elif?else語(yǔ)句)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
簡(jiǎn)單介紹Python中用于求最小值的min()方法
這篇文章主要介紹了簡(jiǎn)單介紹Python中用于求最小值的min()方法,是Python入門(mén)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-05-05
Python實(shí)現(xiàn)GIF動(dòng)圖以及視頻卡通化詳解
本文主要介紹了如何使用Python中的animegan2-pytorch實(shí)現(xiàn)動(dòng)圖以及視頻的卡通化效果,文中的代碼具有一定的學(xué)習(xí)價(jià)值,需要的朋友可以參考一下2021-12-12
跟老齊學(xué)Python之for循環(huán)語(yǔ)句
看這個(gè)標(biāo)題,有點(diǎn)匪夷所思嗎?為什么for是難以想象的呢?因?yàn)樵趐ython中,它的確是很常用而且很強(qiáng)悍,強(qiáng)悍到以至于另外一個(gè)被稱之為迭代的東西,在python中就有點(diǎn)相形見(jiàn)絀了。在別的語(yǔ)言中,for的地位從來(lái)沒(méi)有如同python中這么高的。2014-10-10
Python類的動(dòng)態(tài)綁定實(shí)現(xiàn)原理
這篇文章主要介紹了Python類的動(dòng)態(tài)綁定實(shí)現(xiàn)原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
python PyAUtoGUI庫(kù)實(shí)現(xiàn)自動(dòng)化控制鼠標(biāo)鍵盤(pán)
這篇文章主要介紹了python PyAUtoGUI庫(kù)實(shí)現(xiàn)自動(dòng)化控制鼠標(biāo)鍵盤(pán),幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-09-09

