如何獲取 Pyplot 中某個圖形的座標軸列表?
為了獲得一個圖形的座標軸列表,我們首先會建立一個圖形然後使用 get_axes() 方法來獲得座標軸並設定這些座標軸的標籤。
- 使用 numpy 建立 x 和 y 軸,使用 figure() 方法建立 fig。建立一個新的圖形,或者啟用一個已有的圖形。
- 使用 add_subplot() 方法。把一個 '~.axes.Axes' 新增到該圖形的子圖佈局中,其中 nrows=1, ncols=1 且 index=1.
- 獲取 fig 的座標軸,並設定 xlabel 和 ylabel。
- 使用紅色繪製 x 和 y 的資料點。
- 使用 show() 方法來顯示圖形。
示例
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
xs = np.linspace(1, 10, 10)
ys = np.tan(xs)
fig = plt.figure()
ax = fig.add_subplot(111)
fig.get_axes()[0].set_ylabel("Y-Axis")
fig.get_axes()[0].set_xlabel("X-Axis")
ax.plot(xs, ys, c='red')
plt.show()輸出

廣告
資料結構
網路
關係型資料庫管理系統(RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP