Hello everyone,
I've come to ask you for a service that I don't know how to do. It's something quite complicated for me, being inexperienced in the field.
I'm using a library called "corner" to display 1D (or 2D) histograms. I use it particularly for drawing contours. These contours correspond to density contours because, initially, the data correspond to simple points on the graph (mass on radius). The aim is to calculate the density of these points and define contours of a certain density.
I've managed to display these contours, but I want to extract the coordinates of the various contours, and that's where I get totally stuck.
Here's an overview of the graph and the code, maybe it'll help you and I'd like to thank you in advance for any help you can give me.
import numpy as np
import matplotlib.pyplot as plt
import corner
data = np.loadtxt('[a file with mass and radius]')
masse = data[:, 0]
rayon = data[:, 1]
bin_size = [0.1, 0.05]
num_bins_masse = int((max(masse) - min(masse)) / bin_size[0])
num_bins_rayon = int((max(rayon) - min(rayon)) / bin_size[1])
contour_colors = ['red', 'green', 'blue']
hist, x_edges, y_edges = np.histogram2d(masse, rayon, bins=[num_bins_masse, num_bins_rayon])
# /!\ Proba density
total_points = np.sum(hist)
probabilities = hist / total_points
figure = corner.hist2d(masse, rayon, contour_kwargs={'colors': contour_colors}, levels=[0.68, 0.95, 0.9999], bins=[num_bins_masse, num_bins_rayon])
plt.xlabel('Rayon (km)')
plt.ylabel('Masse (Msun)')
plt.title('Contours de densité des échantillons MCMC')
# Afficher le plot
plt.show()