Correlogram
Stellar Classification Features
Astrophysics correlogram of stellar properties by spectral class
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
np.random.seed(987)
n = 160
spectral = np.random.choice(['O/B', 'F/G', 'K/M'], n)
data = {
'Temp (K)': np.where(spectral == 'O/B', np.random.normal(25000, 8000, n),
np.where(spectral == 'F/G', np.random.normal(6000, 800, n), np.random.normal(4000, 500, n))),
'Luminosity': np.where(spectral == 'O/B', np.random.lognormal(4, 1, n),
np.where(spectral == 'F/G', np.random.lognormal(0, 0.5, n), np.random.lognormal(-1, 0.4, n))),
'Mass (M☉)': np.where(spectral == 'O/B', np.random.normal(15, 5, n),
np.where(spectral == 'F/G', np.random.normal(1, 0.2, n), np.random.normal(0.5, 0.15, n))),
'Radius (R☉)': np.where(spectral == 'O/B', np.random.normal(8, 3, n),
np.where(spectral == 'F/G', np.random.normal(1, 0.2, n), np.random.normal(0.6, 0.1, n))),
'Class': spectral
}
df = pd.DataFrame(data)
plt.style.use('dark_background')
sns.set_style("darkgrid", {'axes.facecolor': '#0a0a0f', 'figure.facecolor': '#0a0a0f', 'grid.color': '#333333'})
palette = {'O/B': '#27D3F5', 'F/G': '#F5D327', 'K/M': '#C82909'}
g = sns.pairplot(
df,
hue='Class',
palette=palette,
height=2,
kind='scatter',
diag_kind='kde',
markers=['*', 'o', 's'],
plot_kws={'alpha': 0.75, 's': 60, 'edgecolor': 'white', 'linewidths': 0.5},
diag_kws={'alpha': 0.5, 'linewidth': 2.5, 'fill': True}
)
g.fig.set_facecolor('#0a0a0f')
for ax in g.axes.flat:
if ax:
ax.set_facecolor('#0a0a0f')
for spine in ax.spines.values():
spine.set_color('#333333')
ax.tick_params(colors='#888888')
ax.xaxis.label.set_color('white')
ax.yaxis.label.set_color('white')
g.fig.suptitle('Stellar Properties by Spectral Class', fontsize=14, fontweight='bold', color='white', y=1.02)
plt.setp(g._legend.get_title(), color='white')
plt.setp(g._legend.get_texts(), color='white')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Correlogram examples
☕