Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีปรับขนาดแกนใน Mplot3d (Matplotlib 3D)


ตั้งค่าช่วงแกน x, y, z ในกราฟ 3D

ใช้ set_xlim3d, set_ylim3d, set_zlim3d

ขั้นตอน

  1. สร้าง figure ด้วย figure()
  2. สร้าง axes 3D ด้วย Axes3D()
  3. ปรับแกน X ด้วย set_xlim3d()
  4. ปรับแกน Y ด้วย set_ylim3d()
  5. ปรับแกน Z ด้วย set_zlim3d()
  6. แสดงด้วย show()

ตัวอย่างโค้ด

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()

ผลลัพธ์

วิธีปรับขนาดแกนใน Mplot3d (Matplotlib 3D)