Python 金融資料視覺效果(兩列資料的提取//分別畫//雙座標軸//雙圖//兩種不同的圖)

來源:互聯網
上載者:User

標籤:gen   線圖   print   and   double   size   資料視覺效果   sub   span   

import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.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 mplimport numpy as npimport matplotlib.pyplot as pltnp.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()

3.雙座標軸。

import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100fig,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 mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100plt.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 mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100plt.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 金融資料視覺效果(兩列資料的提取//分別畫//雙座標軸//雙圖//兩種不同的圖)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.