Stanislav Hronek
Stanislav Hronek

Reputation: 63

How to connect points in python ax.scatter 3D plot

I have a 3D plot in python which I made using ax.scatter(x,y,z,c='r',s=100) from the

import matplotlib.pyplot as plt

import pylab

from mpl_toolkits.mplot3d import Axes3D.

I want to connect my points with a line. I know you can do it with marker='-o' but that works only in 2D for me and not 3D. Can anyone help ? Thank you.

Upvotes: 6

Views: 16005

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339795

Scatter does not allow for connecting points. The argument marker='-o' only works for plot, not for scatter. That is true for 2D and 3D. But of course you can use a scatter and a plot

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

ax = plt.gca(projection="3d")
x,y,z = [1,1.5,3],[1,2.4,3],[3.4,1.4,1]
ax.scatter(x,y,z, c='r',s=100)
ax.plot(x,y,z, color='r')

plt.show()

enter image description here

Upvotes: 10

Related Questions