I need to plot a scatter graph for a Astrophysics project report. This graph is a plot of ‘colour’ against ‘spectral type’
On the Y-axis is ‘J-K’, a numerical value, and X-axis is ‘Spectral type, which ranges from M7, M7.5, M8.5, M9, M9.5, L0, L0.5, L1, L1.5, L2, L2.5 etc. This paper on page 86 provides an example of what I want to replicate: https://arxiv.org/pdf/1108.4677
Whilst I have managed to plot this graph for one csv file dataset, (I changed the spectral types M8, L3 etc to numerical values and will photo-shop the correct label) I need to add on a second set of data onto the same graph but mark them differently. For my masters project I have discovered new astronomical objects and need to compare them to previously known objects. I though the best way of doing this is to how old, known data in blue, and new data in red, on the same colour-spectral type graph.
I know this is something that should be very simply, but for the life of me I can’t work it out myself and can’t find a clear answer online.
my csv file data looks like this:
My newly discovered objects
A sample of known objects, the full file has 200 objects
Here is the code I successfully used to plot one csv file.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('Known BDs (J-K).csv')
names = df['Name']
spectral_types = df['Spectral type']
j_minus_k = df['J-K']
err_j_minus_k = df['J-K err']
numeric_spectral_types = []
for st in spectral_types:
try:
numeric_spectral_types.append(float(st[1:])) # Extract numeric part and convert to float
except ValueError:
numeric_spectral_types.append(float('nan')) # If conversion fails, set to NaN
plt.errorbar(numeric_spectral_types, j_minus_k, yerr=err_j_minus_k, fmt='o', markersize=5, capsize=3)
plt.ylabel('J-K')
plt.xlabel('Spectral type')
plt.xlabel('Spectral type')
plt.ylabel('J-K')
plt.title('Scatter Plot of J-K vs. Spectral type with Error Bars')
plt.grid(True)
plt.tight_layout()
plt.show()
Berenice L is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.