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

วิธีได้ผิว 3D สีผ่าน Python

ในการได้ผิว 3D สีผ่าน Python สามารถทำตามขั้นตอนดังนี้:

ขั้นตอน

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots

  • สร้างข้อมูล x และ y ด้วย numpy

  • ได้ข้อมูล 3D คือ z

  • สร้าง figure ใหม่หรือ activate existing figure

  • ได้ 3D axes

  • สร้าง surface plot

  • แสดงรูปด้วยเมธอด show()

ตัวอย่าง

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-3, 3, 100)
y = np.cos(x)
x, y = np.meshgrid(x, y)
z = x ** 2 + y ** 2 - 2
fig = plt.figure()
ax = plt.axes(projection='3d')
surf = ax.plot_surface(x, y, z, cmap=plt.get_cmap('hot'), edgecolor='none')
plt.show()

ผลลัพธ์

จะแสดงผิว 3D โค้งโค้ง สีตาม colormap 'hot' ไม่มีขอบ

วิธีได้ผิว 3D สีผ่าน Python