Recently, I was working on a data visualization project where I had to compare multiple 3D scatter plots side by side. Since I often use Python Matplotlib for creating visualizations, I wanted to create 3D scatter subplots to analyze patterns across different datasets.
However, when I first tried it, I realized that while creating a single 3D scatter plot in Python is easy, adding multiple 3D plots in one figure requires a few extra steps.
So, I decided to write this detailed guide to help you understand how to create and customize 3D scatter subplots in Matplotlib easily.
In this tutorial, I’ll show you everything I’ve learned from my experience, from setting up the environment to plotting multiple 3D subplots, customizing colors, and adding titles.
What is a 3D Scatter Plot in Python?
A 3D scatter plot is a type of chart that displays data points in three dimensions, X, Y, and Z. It’s one of the most effective ways to visualize relationships among three numerical variables.
In Python, you can create 3D scatter plots using the mpl_toolkits.mplot3d module of Matplotlib. This module provides the Axes3D class, which allows you to add 3D plotting capabilities to your figures.
When you combine this with subplots, you can visualize multiple 3D datasets side by side — perfect for comparison and analysis.
Method 1 – Create a Simple 3D Scatter Subplot in Python
Let’s start with a basic example. In this method, I’ll show you how to create two 3D scatter subplots in one figure using Matplotlib.
Here’s the complete Python code:
# Import necessary libraries
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Generate random data for demonstration
np.random.seed(42)
x1 = np.random.rand(50)
y1 = np.random.rand(50)
z1 = np.random.rand(50)
x2 = np.random.rand(50)
y2 = np.random.rand(50)
z2 = np.random.rand(50)
# Create a figure with two 3D subplots
fig = plt.figure(figsize=(12, 6))
# First subplot
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax1.scatter(x1, y1, z1, c='blue', marker='o')
ax1.set_title('3D Scatter Plot - Dataset 1')
ax1.set_xlabel('X Axis')
ax1.set_ylabel('Y Axis')
ax1.set_zlabel('Z Axis')
# Second subplot
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
ax2.scatter(x2, y2, z2, c='red', marker='^')
ax2.set_title('3D Scatter Plot - Dataset 2')
ax2.set_xlabel('X Axis')
ax2.set_ylabel('Y Axis')
ax2.set_zlabel('Z Axis')
# Adjust layout and display
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

This code creates two 3D scatter plots side by side, one in blue and one in red. Each subplot has its own title and labeled axes, making it easy to compare datasets visually.
Method 2 – Use plt.subplots() with 3D Projection
When I started creating multiple subplots, I found that using plt.subplots() gives more flexibility. It allows you to easily control the layout and share settings between subplots.
Here’s how you can do it in Python:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create random data
np.random.seed(10)
x = np.random.randn(100)
y = np.random.randn(100)
z = np.random.randn(100)
# Create subplots with 3D projection
fig, axes = plt.subplots(1, 3, subplot_kw={'projection': '3d'}, figsize=(15, 5))
# Plot data in each subplot
colors = ['green', 'orange', 'purple']
titles = ['Region A', 'Region B', 'Region C']
for i, ax in enumerate(axes):
ax.scatter(x, y, z, c=colors[i], marker='o')
ax.set_title(f'3D Scatter - {titles[i]}')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

This method is more scalable. You can easily create 2, 3, or even 6 subplots by adjusting the number of rows and columns in plt.subplots().
Method 3 – Add Color Mapping to 3D Scatter Subplots
Sometimes, you may want to add more depth to your 3D scatter plots by coloring the points based on a variable. This can make your visualization more meaningful and easier to interpret.
Here’s how I do it in Python:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Generate data
np.random.seed(20)
x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
c = x + y + z # color based on combined value
# Create figure and subplots
fig = plt.figure(figsize=(12, 5))
# First subplot with 'viridis' colormap
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
sc1 = ax1.scatter(x, y, z, c=c, cmap='viridis')
ax1.set_title('3D Scatter with Viridis Colormap')
fig.colorbar(sc1, ax=ax1, shrink=0.5, aspect=10)
# Second subplot with 'plasma' colormap
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
sc2 = ax2.scatter(x, y, z, c=c, cmap='plasma')
ax2.set_title('3D Scatter with Plasma Colormap')
fig.colorbar(sc2, ax=ax2, shrink=0.5, aspect=10)
plt.tight_layout()
plt.show()You can see the output in the screenshot below.

In this example, I used the Viridis and Plasma colormaps to visualize the variation in data.
Color mapping helps highlight patterns that might be difficult to see otherwise.
Method 4 – Create a 3D Scatter Subplot Grid (2×2 Layout)
If you work with multiple datasets, creating a grid of 3D scatter plots can be extremely useful. This layout is ideal for comparing four different conditions or regions in one figure.
Here’s a Python example:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Generate random data for four datasets
np.random.seed(30)
data = [np.random.rand(50, 3) for _ in range(4)]
colors = ['blue', 'red', 'green', 'orange']
titles = ['North', 'South', 'East', 'West']
# Create a 2x2 grid of 3D subplots
fig, axes = plt.subplots(2, 2, subplot_kw={'projection': '3d'}, figsize=(12, 10))
for i, ax in enumerate(axes.flat):
x, y, z = data[i][:,0], data[i][:,1], data[i][:,2]
ax.scatter(x, y, z, c=colors[i], marker='o', s=50)
ax.set_title(f'3D Scatter Plot - {titles[i]}')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
plt.tight_layout()
plt.show()This 2×2 subplot grid is highly effective when you need to visually compare multiple datasets side by side. It’s a great way to present results in analytics or research reports.
Customize 3D Scatter Subplots in Python
Once you’ve created your subplots, you can further customize them to make your visualizations stand out.
Here are a few customization tips I often use:
- Change marker size using the s parameter in scatter().
- Add transparency with the alpha parameter.
- Rotate the view using ax.view_init(elev, azim) to get the best angle.
- Add gridlines or remove them with ax.grid(True/False).
- Adjust spacing between subplots using plt.subplots_adjust().
Here’s a quick example of rotating a 3D subplot:
ax.view_init(elev=25, azim=45)This gives a better perspective of the data, especially when points overlap.
When to Use 3D Scatter Subplots in Python
From my experience, 3D scatter subplots are most useful when you need to:
- Compare multiple datasets visually.
- Explore relationships among three continuous variables.
- Present results in a visually engaging way.
- Analyze geographical or spatial data (e.g., U.S. regional sales or population density).
If you’re working in data science, engineering, or business analytics, mastering 3D subplots in Python is an essential skill.
Conclusion
So that’s how you can create and customize 3D scatter subplots in Python using Matplotlib.
We explored multiple methods, from basic subplots to color mapping and grid layouts.
I prefer using the plt.subplots() approach because it gives me more control and scalability. But if you’re just starting, the add_subplot() method is a great way to understand the basics.
Try experimenting with different colormaps, markers, and layouts to see what works best for your data. Once you get comfortable, you’ll find that 3D scatter subplots can make your Python visualizations far more powerful and insightful.
You may read:
- How to Rotate a 3D Scatter Plot in Python Matplotlib
- Create Matplotlib 3D Scatter Plot with Line and Surface
- Create a Transparent 3D Scatter Plot in Python Matplotlib
- Customize 3D Scatter Axis Ticks in Matplotlib

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.