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

การพลอต Scatter 3D ไม่มีแกนและกริดใน Matplotlib

ใช้ ax.scatter() บน axes 3D แล้วปิดแกนและกริดทั้งหมดด้วย ax.axis('off') ได้ scatter 3D แบบ minimalist สะอาดตา

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

  1. ตั้งค่าขนาดรูปและเลย์เอาต์
  2. สร้าง figure และ axes 3D
  3. สร้างข้อมูล xs, ys, zs แบบสุ่ม
  4. พลอต scatter 3D ด้วย ax.scatter() กำหนด colormap
  5. ปิดแกนด้วย ax.axis('off')
  6. แสดงผล

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

import numpy as np
from matplotlib import pyplot as plt

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

fig = plt.figure()
ax = fig.add_subplot(projection="3d")

xs = np.random.rand(100)
ys = np.random.rand(100)
zs = np.random.rand(100)

ax.scatter(xs, ys, zs, c=xs, cmap="copper")
ax.axis('off')
plt.show()

ผลลัพธ์

การพลอต Scatter 3D ไม่มีแกนและกริดใน Matplotlib