I tried to learn seaborn and pandas librairies in Python, by using an Excel document I created before, which contain many datas on 50 stars (e.g. radius, mass, magnitude, temperature, luminosity, distance from Earth and spectral type) Download the file
This is my code
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
stars=pd.read_excel('stars.xlsx')
size={'LBV': 500, 'W': 400, 'O': 250, 'B': 200, 'A': 150, 'F': 100, 'G': 75, 'K': 50, 'M': 30}
s=[str(size[t]) for t in stars['Type']]
palette={
'LBV': 'tab:blue',
'W': 'tab:black',
'O': 'tab:blue',
'B': 'tab:blue',
'A': 'tab:blue',
'F': 'tab:yellow',
'G': 'tab:orange',
'K': 'tab:orange',
'M': 'tab:red'
}
palette=[palette[t] for t in stars['Type']]
fig=sns.catplot(x='Temperature', y='Luminosity', data=stars, hue='Type', height=8, s=15)
fig.set(yscale='log')
for ax in fig.axes[0]:
ax.invert_xaxis()
plt.show()
So with this code I'm trying to 'reproduce' the Hertzsprung-Russel diagram (https://image.shutterstock.com/image-illustration/hertzsprung-russell-diagram-scatter-graph-600w-138787793.jpg) and that's why I want to change the color of the different points depending on their spectral type (changing the palette color of the 'hue') and change also change the size of the stars depending on their spectral type.
I searched on Internet how to do it with Seaborn, and the only answer I got is to put a list to attribute s and palette.
But when I do it:
- for the color palette only, no errors but all scatter become blue (before they had different color because of the 'hue' parameter)
- for the size, I get an error saying
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
I don't really understand why it's not working, based on what I saw on Internet it's supposed to work. Either the website were wrong or it's just another level of understanding Python to me.