【Python畫圖】繪製雙座標圖

使用Python繪製雙座標圖,代碼及結果顯示如下。

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10,6))
#顯示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
ax1 = fig.add_subplot(111)
ax1.plot(df['yearmonth'], df['new'],)
ax1.set_ylabel('每月新增投資者數目(單位:萬戶)',fontdict={'weight': 'normal', 'size': 15})
ax1.set_title("投資者用戶數統計",fontdict={'weight': 'normal', 'size': 15})

ax2 = ax1.twinx()  # this is the important function
ax2.plot(df['yearmonth'], df['total'], 'r')
ax2.set_ylabel('總投資者數目(單位:萬戶)',fontdict={'weight': 'normal', 'size': 15})
ax2.set_xlabel('Same')
#參數rotation設置座標旋轉角度,參數fontdict設置字體和字體大小
ax1.set_xticklabels(df['yearmonth'],rotation=90,fontdict={'weight': 'normal', 'size': 15})

plt.show()

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章