DavidC.
DavidC.

Reputation: 677

matplotlib's scatter module does not behave as expected with "color" and "marker" options in 3D plots

When using matplotlib's scatter module for plotting scattered data on 3D, the options color and marker do not behave as expected, e.g., color='r', marker='o' produce blue dots surrounded by red circles, instead of just filled red circles.

Why this is happening?

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

enter image description here

Upvotes: 2

Views: 241

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339052

The code from the question produces the expected plot with red points in matplotlib 2.0.2. If you have an older version, this may be different.

Other than

ax.scatter(x, y, z, color='r', marker='o')

You may also try to use the c argument, which is usually meant to define the color of a scatter

ax.scatter(x, y, z, c='r', marker='o')

You may also use the facecolors argument

ax.scatter(x, y, z, facecolors='r', marker='o')

Upvotes: 3

Related Questions