Question #5855   Submitted by Answiki on 02/04/2022 at 11:21:46 AM UTC

How to make a 3D scatter plot in Matplotlib?

Answer   Submitted by Answiki on 02/04/2022 at 11:29:14 AM UTC

In Python, the best way to make a 3D scatter plot is to use Matplotlib 3D scatterplot. The following example shows how to plot random points created with NumPy:

# Import numpy and matplotlib
import numpy as np
import matplotlib.pyplot as plt
  
# Creating dataset of 500 random points 
x = np.random.randint(10, size =(500))
y = np.random.randint(20, size =(500))
z = np.random.randint(40, size =(500))

# Creating 3D figure
fig = plt.figure(figsize = (10, 10))
ax = plt.axes(projection ="3d")
 
# Plot data
ax.scatter3D(x, y, z, color = "blue")
 
# Show plot
plt.show()

.The above code should display something like:


Note that scatter3D also accepts lists, the folowing will produce the same result as the above figure:

ax.scatter3D(list(x), list(y), list(z), color = "blue")

3 events in history
Answer by Answiki on 02/04/2022 at 11:29:14 AM

In Python, the best way to make a 3D scatter plot is to use Matplotlib 3D scatterplot. The following example shows how to plot random points created with NumPy:

# Import numpy and matplotlib
import numpy as np
import matplotlib.pyplot as plt
  
# Creating dataset of 500 random points 
x = np.random.randint(10, size =(500))
y = np.random.randint(20, size =(500))
z = np.random.randint(40, size =(500))

# Creating 3D figure
fig = plt.figure(figsize = (10, 10))
ax = plt.axes(projection ="3d")
 
# Plot data
ax.scatter3D(x, y, z, color = "blue")
 
# Show plot
plt.show()

.The above code should display something like:


Note that scatter3D also accepts lists, the folowing will produce the same result as the above figure:

ax.scatter3D(list(x), list(y), list(z), color = "blue")

Answer by Answiki on 02/04/2022 at 11:28:35 AM

In Python, the best way to make a 3D scatter plot is to use Matplotlib 3D scatterplot. The example above shows how to plot random points created with NumPy:

# Import numpy and matplotlib
import numpy as np
import matplotlib.pyplot as plt
  
# Creating dataset of 500 random points 
x = np.random.randint(10, size =(500))
y = np.random.randint(20, size =(500))
z = np.random.randint(40, size =(500))

# Creating 3D figure
fig = plt.figure(figsize = (10, 10))
ax = plt.axes(projection ="3d")
 
# Plot data
ax.scatter3D(x, y, z, color = "blue")
 
# Show plot
plt.show()

.The above code should display something like:


Note that scatter3D also accepts lists, the folowing will produce the same result as the above figure:

ax.scatter3D(list(x), list(y), list(z), color = "blue")

Question by Answiki 02/04/2022 at 11:21:46 AM
How to make a 3D scatter plot in Matplotlib?
# ID Query URL Count

Icons proudly provided by Friconix.