matplotlib 的散点图模块在 3D 绘图中使用 "color" 和 "marker" 选项时的行为与预期不符
matplotlib's scatter module does not behave as expected with "color" and "marker" options in 3D plots
当使用 matplotlib
的 scatter
模块在 3D 上绘制散点数据时,选项 color
和 marker
的行为不符合预期,例如,
color='r', marker='o'
生成被红色圆圈包围的蓝点,而不是仅仅填充红色圆圈。
为什么会这样?
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
N = 100
x = 0.9 * np.random.rand(N)
y = 0.9 * np.random.rand(N)
z = 0.9 * np.random.rand(N)
##### Plotting:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(x, y, z, color='r', marker='o')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
问题中的代码在 matplotlib 2.0.2 中生成了带有红点的预期图。如果您有旧版本,这可能会有所不同。
以外
ax.scatter(x, y, z, color='r', marker='o')
您也可以尝试使用 c
参数,它通常用于定义散点图的颜色
ax.scatter(x, y, z, c='r', marker='o')
您也可以使用 facecolors
参数
ax.scatter(x, y, z, facecolors='r', marker='o')
当使用 matplotlib
的 scatter
模块在 3D 上绘制散点数据时,选项 color
和 marker
的行为不符合预期,例如,
color='r', marker='o'
生成被红色圆圈包围的蓝点,而不是仅仅填充红色圆圈。
为什么会这样?
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
N = 100
x = 0.9 * np.random.rand(N)
y = 0.9 * np.random.rand(N)
z = 0.9 * np.random.rand(N)
##### Plotting:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(x, y, z, color='r', marker='o')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
问题中的代码在 matplotlib 2.0.2 中生成了带有红点的预期图。如果您有旧版本,这可能会有所不同。
以外ax.scatter(x, y, z, color='r', marker='o')
您也可以尝试使用 c
参数,它通常用于定义散点图的颜色
ax.scatter(x, y, z, c='r', marker='o')
您也可以使用 facecolors
参数
ax.scatter(x, y, z, facecolors='r', marker='o')