教育行業(yè)A股IPO第一股(股票代碼 003032)

全國(guó)咨詢(xún)/投訴熱線:400-618-4000

Python培訓(xùn)實(shí)例:2017年7月與2019年7月國(guó)際外匯市場(chǎng)美元/人民幣匯率走勢(shì)

更新時(shí)間:2022年03月29日10時(shí)45分 來(lái)源:傳智教育 瀏覽次數(shù):

  匯率又稱(chēng)外匯利率,指兩種貨幣之間兌換的比率,亦可視為一個(gè)國(guó)家貨幣對(duì)另一種貨幣的價(jià)值。匯率會(huì)受諸多外界因素的影響而出現(xiàn)上下波動(dòng),從而產(chǎn)生貨幣貶值和貨幣升值的現(xiàn)象。已知2017年7月與2019年7月國(guó)際外匯市場(chǎng)美元/人民幣的匯率如表4-4所示。

  表4-4 2017年7月與2019年7月美元/人民幣的匯率

2017年7月與2019年美元比人民幣匯率表

  根據(jù)表4-4的數(shù)據(jù),將“日期”一列的數(shù)據(jù)作為x軸的刻度范圍,將“2017年匯率”和“2019年匯率”兩列數(shù)據(jù)作為y軸的數(shù)據(jù),使用plot()函數(shù)分別繪制反映2017年7月與2019年7月美元/人民幣匯率走勢(shì)的折線圖,并使用實(shí)線和長(zhǎng)虛線進(jìn)行區(qū)分,具體代碼如下。

# 02_dollar_RMB_exchange_rate
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
# 匯率
eurcny_2017 = np.array([6.8007, 6.8007, 6.8015, 6.8015, 6.8060,
                        6.8060, 6.8060, 6.8036, 6.8025, 6.7877,
                        6.7835, 6.7758, 6.7700, 6.7463, 6.7519,
                        6.7511, 6.7511, 6.7539, 6.7265])
eurcny_2019 = np.array([6.8640, 6.8705, 6.8697, 6.8697, 6.8697,
                        6.8881, 6.8853, 6.8856, 6.8677, 6.8662,
                        6.8662, 6.8662, 6.8827, 6.8761, 6.8635,
                        6.8860, 6.8737, 6.8796, 6.8841])
date_x = np.array([3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                   13, 14, 17, 18, 19, 24, 25, 26, 31])
figure = plt.figure()
ax = figure.add_subplot(111)
# 第1條折線:湖綠色, 實(shí)線, 線寬為 2
ax.plot(date_x, eurcny_2017, color='#006374', linewidth=2,
        label='2017年7月美元/人民幣匯率')
# 第2條折線:紫色, 長(zhǎng)虛線, 線寬為2
ax.plot(date_x, eurcny_2019, color='#8a2e76', linestyle='--',
        linewidth=2, label='2019年7月美元/人民幣匯率')
ax.set_title('2017年7月與2019年7月美元/人民幣匯率走勢(shì)')
ax.set_xlabel('日期')
ax.set_ylabel('匯率')
ax.legend()
plt.show()

  運(yùn)行程序,效果如圖4-3所示。

2017年7月與2019年7月國(guó)際外匯市場(chǎng)美元/人民幣匯率的折線圖

  圖4-3 2017年7月與2019年7月國(guó)際外匯市場(chǎng)美元/人民幣匯率的折線圖

  圖4-3中,紫色的虛線代表2019年7月的匯率,湖綠色的實(shí)線代表2017年7月的匯率。由圖4-3可知,2019年7月的匯率呈現(xiàn)較為平穩(wěn)的趨勢(shì),2017年7月的匯率呈現(xiàn)下降趨勢(shì)。

0 分享到:
和我們?cè)诰€交談!