Để lấy danh sách trục của hình, tạo hình rồi dùng get_axes() để lấy trục và đặt nhãn.
- Tạo xs, ys bằng numpy và fig bằng figure().
- Dùng add_subplot() thêm trục vào hình.
- Lấy trục của fig, đặt xlabel và ylabel.
- Vẽ x, y màu đỏ.
- Hiển thị bằng show().
Ví dụ
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()
Kết quả
