Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Điều chỉnh giá trị alpha (độ trong suốt) trên 3D scatter plot Matplotlib

Để kiểm soát độ trong suốt (alpha) của điểm trên 3D scatter, thiết lập facecolors và edgecolors với giá trị RGBA (alpha channel).

Các bước

  • Thiết lập figure size và autolayout.
  • Tạo figure và axes 3D.
  • Tạo dữ liệu x, y, z ngẫu nhiên.
  • Vẽ scatter: s = ax.scatter(x, y, z, c="r").
  • Gán lại setter: s._set_facecolors, s._set_edgecolors = s.set_facecolors, s.set_edgecolors (technique nội bộ).
  • Hiển thị bằng show().

Ví dụ

import numpy as np
import matplotlib.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')
x = np.random.sample(20)
y = np.random.sample(20)
z = np.random.sample(20)
s = ax.scatter(x, y, z, c="r")
s._set_facecolors, s._set_edgecolors = s.set_facecolors, s.set_edgecolors
plt.show()

Kết quả

Điều chỉnh giá trị alpha (độ trong suốt) trên 3D scatter plot Matplotlib