Error Bar Chart

Stellar Magnitude Observations

Apparent magnitude measurements of bright stars with observational uncertainty on light background.

Output
Stellar Magnitude Observations
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Stellar magnitude observations
stars = ['Sirius', 'Canopus', 'Arcturus', 'Vega', 'Capella', 'Rigel', 'Betelgeuse']
magnitude = np.array([-1.46, -0.72, -0.05, 0.03, 0.08, 0.13, 0.42])
uncertainty = np.array([0.02, 0.03, 0.02, 0.01, 0.02, 0.03, 0.05])

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

colors = ['#4927F5', '#276CF5', '#27D3F5', '#27F5B0', '#6CF527', '#F5B027', '#F54927']

for i, (s, m, u, c) in enumerate(zip(stars, magnitude, uncertainty, colors)):
    ax.errorbar(i, m, yerr=u, fmt='o', color=c, ecolor=c,
                elinewidth=2, capsize=6, capthick=2, markersize=14,
                markeredgecolor='#1f2937', markeredgewidth=1.5, alpha=0.9)

ax.invert_yaxis()  # Brighter stars have lower magnitude
ax.axhline(y=0, color='#9ca3af', linestyle='--', linewidth=1, alpha=0.5)

ax.set_xlabel('Star', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Apparent Magnitude', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Brightest Stars: Apparent Magnitude Measurements', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(range(len(stars)))
ax.set_xticklabels(stars, rotation=45, ha='right')
ax.tick_params(colors='#6b7280', labelsize=9)
ax.grid(True, axis='y', alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support