欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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 中單例模式的實現方法

    Python 中單例模式的實現方法

    這篇文章主要介紹了Python 中單例模式的實現方法,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,感興趣的小伙伴可以學習一下下面文章詳細內容
    2022-08-08
  • Python中使用PyQt把網頁轉換成PDF操作代碼實例

    Python中使用PyQt把網頁轉換成PDF操作代碼實例

    這篇文章主要介紹了Python中使用PyQt把網頁轉換成PDF操作代碼實例,本文直接給出實現代碼,需要的朋友可以參考下
    2015-04-04
  • python GUI庫圖形界面開發(fā)之PyQt5表單布局控件QFormLayout詳細使用方法與實例

    python GUI庫圖形界面開發(fā)之PyQt5表單布局控件QFormLayout詳細使用方法與實例

    這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5布局控件QFormLayout詳細使用方法與實例,需要的朋友可以參考下
    2020-03-03
  • python中掃描條形碼和二維碼的實現代碼

    python中掃描條形碼和二維碼的實現代碼

    pyzbar模塊是Python一個開源庫用于掃描和識別二維碼信息。這篇文章主要介紹了python中掃描條形碼和二維碼的示例代碼,需要的朋友可以參考下
    2021-10-10
  • 理解Python垃圾回收機制

    理解Python垃圾回收機制

    這篇文章主要為大家詳細介紹了Python垃圾回收機制,Python中的垃圾回收以引用計數為主,分代收集為輔,想要深入理解Python垃圾回收機制,請閱讀下文
    2016-02-02
  • python入門課程第五講之序列和字符串

    python入門課程第五講之序列和字符串

    這篇文章主要介紹了python入門課程第五講之序列和字符串,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • Django+Celery實現定時任務的示例

    Django+Celery實現定時任務的示例

    Celery是一個基于python開發(fā)的分布式任務隊列,而做python WEB開發(fā)最為流行的框架莫屬Django,本示例使用主要依賴包Django+Celery實現定時任務,感興趣的朋友一起看看吧
    2021-06-06
  • Python入門教程(十八)Python的For循環(huán)

    Python入門教程(十八)Python的For循環(huán)

    這篇文章主要介紹了Python入門教程(十八)Python的For循環(huán),Python是一門非常強大好用的語言,也有著易上手的特性,本文為入門教程,需要的朋友可以參考下
    2023-04-04
  • pycharm+robot開發(fā)及配置指南

    pycharm+robot開發(fā)及配置指南

    這篇文章主要介紹了pycharm+robot開發(fā)指南,包括pycharm配置及robot的配置,本文給大家介紹的非常詳細,需要的朋友可以參考下
    2021-09-09
  • 使用python獲取PDF頁面的大小、方向和旋轉角度

    使用python獲取PDF頁面的大小、方向和旋轉角度

    在文檔管理和自動化領域,了解PDF文檔的內在屬性(如頁面大小、方向和旋轉角度)對于確保一致的文檔處理和布局保真度至關重要,因為它們直接影響文檔的可讀性和用戶體驗,本文將展示如何使用Python代碼獲取PDF文檔中頁面的大小、方向和旋轉角度,需要的朋友可以參考下
    2024-09-09

最新評論