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

Cách tỷ lệ trục (scale axes) trong Mplot3d

Dùng set_xlim3d, set_ylim3d, set_zlim3d để đặt giới hạn 3 trục.

  • fig = plt.figure(), ax = Axes3D(fig).
  • ax.set_xlim3d(-100, 100).
  • ax.set_ylim3d(-100, 100).
  • ax.set_zlim3d(-100, 100).
  • show().

Ví dụ

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim3d(-100, 100)
ax.set_ylim3d(-100, 100)
ax.set_zlim3d(-100, 100)
plt.show()

Kết quả

Khung trục 3D rỗng với phạm vi [-100, 100] cho cả 3 trục.