使用Python和Matplotlib控制3D散点图上的alpha值
要使用Python和Matplotlib控制3D散点图上的alpha值,我们可以设置facecolor和edgecolors值。
- 设置图形大小和子图之间和周围的填充。
- 使用 figure() 方法创建一个新图形或激活现有图形。
- 作为子图布局的一部分,向图形添加 ~.axes.Axes 。
- 使用numpy创建x、y和z数据点。
- 使用 scatter() 方法绘制x、y和z点。
- 设置 facecolors 和 edgecolors 。
- 使用 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()