日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python金融數據可視化匯總

系統 1667 0

通過本篇內容給大家介紹一下Python實現金融數據可視化中兩列數據的提取、分別畫、雙坐標軸、雙圖、兩種不同的圖等代碼寫法和思路總結。

            
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()
          

Python金融數據可視化匯總_第1張圖片

2.下面分別提取兩組數據,進行繪圖。

            
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)

# 重點下面兩種情況的區別
print(y[1])   # 取得是 第1行的數據 [-0.37003581 1.74900181]
print(y[:,0])  # 取得是 第1列的數據 [ 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')

# 添加細節
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()
          

Python金融數據可視化匯總_第2張圖片

Python金融數據可視化匯總_第3張圖片

3.雙坐標軸。

            
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()
          

Python金融數據可視化匯總_第4張圖片

4. 分為兩個圖繪畫。

            
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)        # 確定第一個圖的位置 (行,列,第幾個)兩行一列第一個圖

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)        # 確定第一個圖的位置
plt.plot(y[:,1],'g',label="2st")
plt.plot(y[:,1],'r*')
plt.ylabel("Values of 2st")
plt.legend(loc=0)

plt.show()
          

Python金融數據可視化匯總_第5張圖片

5.在兩個圖層中繪制兩種不同的圖(直線圖立方圖)

            
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)        # 確定第一個圖的位置

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)        # 確定第一個圖的位置
plt.bar(np.arange(len(y[:,1])),y[:,1],width = 0.5,color='g',label="2nd") # 直方圖的畫法
plt.grid(True)
plt.xlabel("Index")
plt.title('2nd date set')
plt.legend(loc=0)

plt.show()
          

Python金融數據可視化匯總_第6張圖片

以上就是本次交給大家的Python制作金融數據等用到的圖形化界面代碼寫法。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 柏乡县| 治县。| 天祝| 都江堰市| 澜沧| 泰宁县| 襄樊市| 滕州市| 章丘市| 河北区| 渭源县| 扶绥县| 武定县| 肃北| 名山县| 仁化县| 富裕县| 红原县| 扎鲁特旗| 道真| 贡觉县| 沙雅县| 手游| 兴宁市| 镇坪县| 休宁县| 朝阳区| 陵水| 江孜县| 西丰县| 奈曼旗| 八宿县| 宽城| 无极县| 阿瓦提县| 天水市| 佛山市| 武威市| 沙湾县| 连江县| 邓州市|