Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 611
Stanislav Hronek Avatar asked Jun 04 '17 15:06

Stanislav Hronek


People also ask

How to connect points in scatter plot?

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

How to plot a 3D scatter graph with line in Python?

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:

What is a connected scatterplot in Python?

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.

How to plot a 3D plot in Python using matplotlib?

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.


1 Answers

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

like image 163
ImportanceOfBeingErnest Avatar answered Sep 17 '22 21:09

ImportanceOfBeingErnest