Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to turn off transparency in Matplotlib's 3D Scatter plot?
In Matplotlib's 3D scatter plot, transparency effects can make data points appear faded or overlapped. To create solid, non-transparent scatter points, you need to control the alpha and depthshade parameters.
Key Parameters
Two main parameters control transparency in 3D scatter plots:
- alpha − Controls overall transparency (0=transparent, 1=opaque)
- depthshade − When False, prevents automatic depth-based shading
Example
Here's how to create a 3D scatter plot with no transparency effects ?
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Set figure size
plt.rcParams["figure.figsize"] = [8, 6]
plt.rcParams["figure.autolayout"] = True
# Create figure and 3D axis
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Generate random data points
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
z = np.random.rand(N)
# Create scatter plot with no transparency
ax.scatter(x, y, z, c=y, cmap='viridis', alpha=1.0, depthshade=False, s=50)
# Add labels
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.set_title('3D Scatter Plot - No Transparency')
plt.show()
Comparison
| Parameter | Default | For No Transparency | Effect |
|---|---|---|---|
alpha |
1.0 | 1.0 | Fully opaque points |
depthshade |
True | False | No automatic depth shading |
With vs Without Transparency
Compare the effects of different transparency settings ?
import numpy as np
import matplotlib.pyplot as plt
# Create sample data
N = 30
x = np.random.rand(N)
y = np.random.rand(N)
z = np.random.rand(N)
# Create subplots for comparison
fig = plt.figure(figsize=(12, 5))
# Plot 1: With transparency effects
ax1 = fig.add_subplot(121, projection='3d')
ax1.scatter(x, y, z, c=z, cmap='plasma', alpha=0.6, depthshade=True, s=60)
ax1.set_title('With Transparency (alpha=0.6, depthshade=True)')
# Plot 2: Without transparency effects
ax2 = fig.add_subplot(122, projection='3d')
ax2.scatter(x, y, z, c=z, cmap='plasma', alpha=1.0, depthshade=False, s=60)
ax2.set_title('No Transparency (alpha=1.0, depthshade=False)')
plt.tight_layout()
plt.show()
Conclusion
Set alpha=1.0 and depthshade=False to turn off transparency in 3D scatter plots. This creates solid, clearly visible data points without any depth-based fading effects.
Advertisements
