Recently, I was working on a Python project where I needed to visualize customer data in three dimensions: sales, profit, and number of orders. The 3D scatter plot looked great, but I wanted to view it from different angles to better understand the data patterns.
If you’ve ever used Matplotlib for 3D visualization, you’ve probably realized that while creating a 3D scatter plot is easy, changing the view angle can make a huge difference in how you interpret your data.
In this tutorial, I’ll show you how to change the view angle in a 3D scatter plot using Python’s Matplotlib library. I’ll cover multiple methods, from simple static angle changes to interactive and animated rotations.
What is a 3D Scatter Plot in Python Matplotlib?
A 3D scatter plot is a type of plot that displays data points in three-dimensional space using the X, Y, and Z axes. Each point represents a combination of three numerical variables, making it ideal for exploring relationships in complex datasets.
In Python, we can easily create a 3D scatter plot using the Axes3D module from mpl_toolkits.mplot3d. Once you’ve created the plot, you can change the viewing angle to get a better perspective of your data.
Method 1 – Change the View Angle Using view_init() in Python
The simplest way to change the view angle in a 3D scatter plot is by using the view_init() method. This method allows you to set the elevation and azimuth angles manually.
Here’s how you can do it:
Example: Static View Angle Change
# 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)
x = np.random.randint(1, 100, 50)
y = np.random.randint(1, 100, 50)
z = np.random.randint(1, 100, 50)
# Create a 3D figure
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
# Create a scatter plot
ax.scatter(x, y, z, c='blue', marker='o', s=50)
# Set labels
ax.set_xlabel('Sales (in $1000s)')
ax.set_ylabel('Profit (in $1000s)')
ax.set_zlabel('Number of Orders')
# Change the view angle
ax.view_init(elev=30, azim=60)
# Add a title
plt.title('3D Scatter Plot - Changing View Angle in Python', fontsize=14)
# Show the plot
plt.show()You can see the output in the screenshot below.

In this example, I changed the elevation to 30° and the azimuth to 60°. You can experiment with different values to find the best viewing angle for your data.
The elev parameter controls how high the camera is above the XY plane, while azim controls how far around the Z-axis the camera is rotated.
Method 2 – Rotate the 3D Scatter Plot Dynamically
Sometimes, you may want to rotate the 3D scatter plot dynamically to view it from all angles. This is especially useful when presenting your data to others or exploring patterns visually.
Python’s Matplotlib allows you to create an animated rotation using a simple loop.
Example: Rotate 3D Scatter Plot
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import time
# Generate random data
np.random.seed(10)
x = np.random.randn(100)
y = np.random.randn(100)
z = np.random.randn(100)
# Create a 3D figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Create scatter plot
ax.scatter(x, y, z, c='green', marker='^', s=40)
# Set labels
ax.set_xlabel('Latitude')
ax.set_ylabel('Longitude')
ax.set_zlabel('Elevation')
# Rotate the view dynamically
for angle in range(0, 360, 5):
ax.view_init(elev=25, azim=angle)
plt.draw()
plt.pause(0.1)You can see the output in the screenshot below.

This script rotates the 3D scatter plot smoothly through 360 degrees, giving you a full view of your data.
It’s an excellent way to explore complex datasets, especially when you want to identify trends or clusters in three dimensions.
Method 3 – Interactive Rotation in Python Matplotlib
If you prefer a more interactive approach, Matplotlib allows you to manually rotate the 3D scatter plot using your mouse.
This method doesn’t require any additional code; just use the built-in interactivity of Matplotlib’s 3D plots.
Here’s how you can do it:
Example: Interactive 3D Scatter Plot
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create sample data
x = np.random.uniform(0, 50, 100)
y = np.random.uniform(0, 50, 100)
z = np.random.uniform(0, 50, 100)
# Create a 3D scatter plot
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c='red', s=40, alpha=0.8)
# Set labels
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
plt.title('Interactive 3D Scatter Plot in Python')
# Show interactive plot
plt.show()You can see the output in the screenshot below.

When you run this code, you can click and drag the plot to rotate it freely. This is one of my favorite ways to explore 3D data because it gives you full control over the perspective.
Method 4 – Animate the 3D Scatter Plot Using Matplotlib’s Animation Module
If you want a smooth and professional-looking rotation, you can use the FuncAnimation class from Matplotlib’s animation module.
This method is great for creating presentations or exporting animated visualizations.
Example: Animated 3D Scatter Plot
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib.animation import FuncAnimation
# Generate data
np.random.seed(5)
x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
# Create figure and 3D axes
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Create scatter plot
sc = ax.scatter(x, y, z, c=z, cmap='plasma', s=50)
# Function to update the view angle
def update(angle):
ax.view_init(elev=25, azim=angle)
return ax,
# Create animation
ani = FuncAnimation(fig, update, frames=range(0, 360, 2), interval=100)
plt.title('Animated 3D Scatter Plot in Python')
plt.show()This animation smoothly rotates the 3D scatter plot around the Z-axis, giving you a dynamic visualization of your data.
You can even export the animation to a video file using ani.save(‘3d_rotation.mp4’).
Tips for Choosing the Right View Angle
Here are a few tips I’ve learned from experience when working with 3D scatter plots in Python:
- Use moderate elevation angles (20°–40°) for balanced views.
- Avoid extreme azimuth angles unless you want a top-down or side view.
- Combine color and size encoding to add more dimensions to your visualization.
- Use consistent color maps like viridis or plasma for clarity.
Changing the view angle isn’t just cosmetic; it can completely change how you interpret your data.
Common Use Cases
Here are a few real-world scenarios where changing the view angle in Python’s Matplotlib 3D scatter plots can be useful:
- Sales analytics: Visualizing regional sales, profit, and growth across U.S. states.
- Environmental data: Comparing temperature, humidity, and air quality across cities.
- Machine learning: Understanding clusters in high-dimensional datasets.
- Finance: Visualizing stock performance across sectors and time periods.
I hope you found this guide helpful. Changing the view angle in a Matplotlib 3D scatter plot using Python is a simple yet powerful way to enhance your data visualization.
Whether you use view_init() for static views, animation for dynamic rotation, or interactive plots for exploration, each method helps you see your data from a new perspective.
Experiment with different angles and techniques until you find the one that best tells your story.
You may also like to read:
- Save a 3D Scatter Plot in Python using Matplotlib
- Create a Matplotlib 3D Scatter Animation in Python
- Set Xlim and Zlim in Matplotlib 3D Scatter Plot
- Create 3D Scatter Plot from a NumPy Array 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.