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.
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
Here we are going to learn how we can plot a 3D scatter graph with line. To connect scatter points, we use the plot3D () method with x, y, and z data points. Let’s see an example where we plot a 3D scatter graph with the line:
A connected scatterplot is a line chart where each data point is shown by a circle or any type of marker. This section explains how to build a connected scatterplot with Python, using both the Matplotlib and the Seaborn libraries. Building a connected scatterplot with Python and Matplotlib is a breeze thanks to the plot () function.
Note that these two steps will be common in most of the 3D plotting you do in Python using Matplotlib. After we create the axes object, we can use it to create any type of plot we want in the 3D space. To plot a single point, we will use the scatter () method, and pass the three coordinates of the point.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With