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 plot a point on 3D axes in Matplotlib?
Matplotlib allows you to create 3D plots and visualize points in three-dimensional space. To plot a point on 3D axes, you need to use the scatter() method with projection='3d'.
Basic 3D Point Plotting
Here's how to plot a single point in 3D space ?
import matplotlib.pyplot as plt
# Set figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
# Create figure with 3D projection
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot a point at coordinates (2, 3, 4)
ax.scatter(2, 3, 4, c='red', marker='*', s=1000)
# Add labels
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
plt.show()
Plotting Multiple Points
You can plot multiple points by passing arrays of coordinates ?
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
# Define multiple points
x_points = [1, 2, 3, 4, 5]
y_points = [2, 4, 1, 3, 5]
z_points = [1, 3, 2, 5, 4]
# Plot multiple points with different colors
colors = ['red', 'blue', 'green', 'orange', 'purple']
ax.scatter(x_points, y_points, z_points, c=colors, s=200)
# Add labels and title
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.set_title('Multiple Points in 3D Space')
plt.show()
Customizing Point Appearance
You can customize points using various parameters ?
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# Plot points with different markers and sizes
ax.scatter(1, 1, 1, c='red', marker='o', s=500, label='Circle')
ax.scatter(2, 2, 2, c='blue', marker='^', s=500, label='Triangle')
ax.scatter(3, 3, 3, c='green', marker='s', s=500, label='Square')
ax.scatter(4, 4, 4, c='orange', marker='*', s=800, label='Star')
# Add labels and legend
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.set_title('Different Point Styles in 3D')
ax.legend()
plt.show()
Key Parameters
| Parameter | Description | Example Values |
|---|---|---|
c |
Point color | 'red', 'blue', '#FF5733' |
marker |
Point shape | 'o', '*', '^', 's' |
s |
Point size | 50, 200, 1000 |
alpha |
Transparency | 0.1 to 1.0 |
Conclusion
Use ax.scatter(x, y, z) with projection='3d' to plot points in 3D space. Customize appearance using color, marker, and size parameters for better visualization.
Advertisements
