Python金融數據可視化匯總
更新時間:2017年11月17日 14:33:52 投稿:laozhang
這篇文章主要介紹了Python金融數據可視化(兩列數據的提取,分別畫,雙坐標軸,雙圖,兩種不同的圖)等內容。
通過本篇內容給大家介紹一下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()
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) # 重點下面兩種情況的區(qū)別 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') # 添加細節(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.雙坐標軸。
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. 分為兩個圖繪畫。
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()
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制作金融數據等用到的圖形化界面代碼寫法。
您可能感興趣的文章:
- 利用Python繪制MySQL數據圖實現數據可視化
- 利用Python代碼實現數據可視化的5種方法詳解
- Python數據可視化正態(tài)分布簡單分析及實現代碼
- 基于Python數據可視化利器Matplotlib,繪圖入門篇,Pyplot詳解
- 利用Python進行數據可視化常見的9種方法!超實用!
- 舉例講解Python的Tornado框架實現數據可視化的教程
- 以911新聞為例演示Python實現數據可視化的教程
- Python實現數據可視化看如何監(jiān)控你的爬蟲狀態(tài)【推薦】
- Python數據可視化編程通過Matplotlib創(chuàng)建散點圖代碼示例
- python3對拉勾數據進行可視化分析的方法詳解
相關文章
python GUI庫圖形界面開發(fā)之PyQt5表單布局控件QFormLayout詳細使用方法與實例
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5布局控件QFormLayout詳細使用方法與實例,需要的朋友可以參考下2020-03-03Python入門教程(十八)Python的For循環(huán)
這篇文章主要介紹了Python入門教程(十八)Python的For循環(huán),Python是一門非常強大好用的語言,也有著易上手的特性,本文為入門教程,需要的朋友可以參考下2023-04-04