使用 Python 和 Matplotlib 控制 3D 散點圖中的 alpha 值


若要使用 Python 和 Matplotlib 控制 3D 散點圖中的 alpha 值,我們可以設定面顏色和邊顏色值。

  • 設定圖形大小並調整子圖之間的空白。
  • 建立一個新圖形或使用 figure() 方法啟用現有圖形。
  • '~.axes.Axes' 作為子圖排列的一部分新增到圖形中。
  • 使用 numpy 建立 x、y 和 z 資料點。
  • 使用 scatter() 方法繪製 x、y 和 z 點。
  • 設定 facecolorsedgecolors。
  • 若要顯示圖形,請使用 show() 方法。

示例

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()

結果

更新於: 2021-06-01

581 次瀏覽

開啟你的 職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.