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

การแยกแยะการฉายแบบ Orthographic และ Perspective ใน Matplotlib


ขั้นตอนการทำงาน

  • กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
  • สร้าง figure ใหม่หรือเปิดใช้งาน figure ที่มีอยู่
  • เพิ่ม axes เข้าไปใน figure เป็นส่วนหนึ่งของ subplot arrangement
  • ตั้งค่า projection type เป็น 'perspective' บน ax1
  • ตั้งชื่อเรื่องของกราฟ
  • เพิ่ม axes เข้าไปใน figure เป็นส่วนหนึ่งของ subplot arrangement
  • ตั้งค่า projection type เป็น 'orthographic' บน ax2
  • ตั้งชื่อเรื่องของกราฟ
  • ใช้เมธอด show() เพื่อแสดงรูปภาพ

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

import matplotlib.pyplot as plt

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

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax1.set_proj_type('persp')
ax1.set_title('Perspective')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
ax2.set_proj_type('ortho')
ax2.set_title('Orthographic')
plt.show()

ผลลัพธ์

การแยกแยะการฉายแบบ Orthographic และ Perspective ใน Matplotlib