Moo
Moo

Reputation: 1

Plotting 2 sets of data onto one graph on Python

This is my python code used to plot 2 sets of code on the same set of axis. I need the simulated code and original code on the same graph so that I can see how well they fit.

import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits


file_path = 'GalCat_extra_lean.fits'
hdul = fits.open(file_path)
data = hdul[1].data


halo_mass = data['mass_halo']
nsat = data['N_sat']

hdul.close()

# Define the halo mass and the mean number of satellites
selected_halo_mass = 1e12  # Selected halo mass in solar masses
mean_nsat = 20  # Mean number of satellites

# Generate simulated measurements using a Poisson sampler
np.random.seed(42)  # for reproducibility
simulated_nsat = np.random.poisson(mean_nsat, size=len(halo_mass)).astype(float)  # Convert to float
mask = halo_mass != selected_halo_mass
simulated_nsat[mask] = np.nan  # Set values to NaN where halo mass is not equal to the selected halo mass

# Plot the scatter plot with original data
plt.figure(figsize=(10, 6))
plt.scatter(halo_mass, nsat, color='blue', alpha=0.5, label='Original Data', s=0.2)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Halo Mass [$M_☉$]')
plt.ylabel('Number of Satellites ($N_{sat}$)')
plt.title('Number of Satellites vs. Halo Mass (log-log)')
plt.grid(True, which="both", ls="--")

# Plot the simulated data as a scatter plot with a different marker style or color
plt.scatter(halo_mass, simulated_nsat, color='red', alpha=0.5, label='Simulated Data', s=0.2, marker='x')

plt.legend()
plt.show()

my plot

i can't get my simulated data to show up on my plot How do i do it?

Upvotes: 0

Views: 33

Answers (0)

Related Questions