บทนำ
3D Scatter Plot แสดงจุดข้อมูลในพื้นที่ 3 มิติ (x, y, z) ช่วยมองความสัมพันธ์ 3 ตัวแปร
การติดตั้ง
pip install matplotlib
Dependencies
Python>=3.4, NumPy, Setuptools, Pyparsing, Libpng, Pytz, FreeType, Six, Cycler, Dateutil
ตัวอย่างโค้ด
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes(projection='3d')
z = np.linspace(0, 1, 100)
x = z * np.sin(20 * z)
y = z * np.cos(20 * z)
ax.scatter(x, y, z, 'blue')
ax.set_xlabel("X-axis")
ax.set_ylabel("Y-axis")
ax.set_zlabel("Z-axis")
ax.set_title('A sample 3D scatter plot')
plt.show()คำอธิบาย
สร้างข้อมูล spiral ด้วย sin/cos
ใช้
ax.scatterพร้อมสีตั้งค่า label 3 แกน