Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Xoay nhãn trục (axes label) trong đồ thị 3D Matplotlib

Để xoay nhãn trục Z (hoặc X, Y) trong đồ thị 3D, truyền tham số rotation vào set_zlabel().

Các bước

  • Thiết lập figure size và autolayout.
  • Tạo figure và axes 3D.
  • Khởi tạo góc xoay angle = 45.
  • Đặt nhãn trục Z: ax.set_zlabel('Z-Axis', rotation=angle).
  • Hiển thị bằng show().

Ví dụ

from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
angle = 45
ax.set_zlabel('Z-Axis', rotation=angle)
plt.show()

Kết quả

Xoay nhãn trục (axes label) trong đồ thị 3D Matplotlib