Pyplot 3D scatter z axis issue

Viewed 19

Is there something wrong with the 3d plt.scatter(x,y,z) method?

Plots all z values at zero:

x = [1, 1]
y = [1, 1]
z = [-10, 10]

fig = plt.figure(figsize=(16, 18))
plt.axes(projection ="3d")
plt.scatter(x, y, z, color='k')

plt.show()

Working correctly:

x = [1, 1]
y = [1, 1]
z = [-10, 10]

fig = plt.figure(figsize=(16, 18))
ax = plt.axes(projection ="3d")
ax.scatter(x, y, z, color='k')

plt.show()
1 Answers

In your above examples you used the two matplotlib's interfaces: pyplot vs object oriented.

If you'll look at the source code of pyplot.scatter you'll see that even if you are going to provide 3 arguments plt.scatter(x, y, z, color='k'), it is actually going to call the 2D version, with x, y, s=z, s being the marker size.

So, it appears that you have to use the object oriented approach to achieve your goals.

Related