Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D points in 2D coordinates
#5
(Jun-06-2023, 05:03 PM)rajeshgk Wrote: To visualize a series of 3D coordinates as a series of 2D scatter plots at specific intervals of the z-plane, you can use a plotting library like Matplotlib.

import numpy as np
import matplotlib.pyplot as plt

# Generate random 3D coordinates
np.random.seed(42)
num_points = 300
x = np.random.randn(num_points)
y = np.random.randn(num_points)
z = np.linspace(0, 10, num_points) # Assuming z values range from 0 to 10

# Specify the intervals of z-plane for which to create scatter plots
z_intervals = [2, 4, 6, 8]

# Create scatter plots for each z interval
for z_interval in z_intervals:
# Filter the coordinates within the current z interval
mask = (z >= z_interval) & (z < z_interval + 1)
x_interval = x[mask]
y_interval = y[mask]

# Create a new figure and scatter plot
plt.figure()
plt.scatter(x_interval, y_interval)
plt.title(f"Scatter Plot at z = {z_interval}")
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
plt.show()

In this example, we generate random 3D coordinates x, y, and z. We then specify the intervals of the z-plane for which we want to create scatter plots in the z_intervals list.

Inside the loop, we filter the coordinates that fall within the current z interval using a boolean mask. We then create a new figure, plot the scatter plot of the filtered coordinates, and customize the plot with a title, labels, and gridlines.

By running this code, you will see a series of scatter plots at the specified intervals of the z-plane, each showing the distribution of points in the x-y plane for that particular z interval.



Thank you. This is really helpful. I will try and get back having further question.
Reply


Messages In This Thread
3D points in 2D coordinates - by sunath - Jun-03-2023, 01:29 AM
RE: 3D points in 2D coordinates - by deanhystad - Jun-03-2023, 01:31 PM
RE: 3D points in 2D coordinates - by DPaul - Jun-04-2023, 05:35 AM
RE: 3D points in 2D coordinates - by rajeshgk - Jun-06-2023, 05:03 PM
RE: 3D points in 2D coordinates - by sunath - Jun-06-2023, 05:09 PM
RE: 3D points in 2D coordinates - by deanhystad - Jun-07-2023, 05:52 PM
RE: 3D points in 2D coordinates - by sunath - Jun-07-2023, 06:32 PM
RE: 3D points in 2D coordinates - by sunath - Jun-07-2023, 06:59 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020