import pandas as pd
import matplotlib.pyplot as plt
Datos
tiendas = ['A', 'B', 'C', 'D']
ventas_2022 = {
'Ene': [100, 80, 150, 50],
'Feb': [120, 90, 170, 60],
'Mar': [150, 100, 200, 80],
'Abr': [180, 110, 230, 90],
'May': [220, 190, 350, 200],
'Jun': [230, 150, 280, 120],
'Jul': [250, 170, 300, 140],
'Ago': [260, 180, 310, 150],
'Sep': [240, 160, 290, 130],
'Oct': [220, 140, 270, 110],
'Nov': [400, 220, 350, 190],
'Dec': [300, 350, 400, 250]
}
Crear DataFrame
df = pd.DataFrame(ventas_2022, index=tiendas)
Colores personalizados para cada tienda
colores = ['#1f77b4', '#2ca02c', '#d62728', '#ff7f0e']
Crear figura
fig, axs = plt.subplots(2, 2, figsize=(14, 8))
fig.suptitle(' Variación Mensual de Ventas por Tienda - Año 2022',
fontsize=20, fontweight='bold', color='darkblue')
meses = list(ventas_2022.keys())
Iterar sobre cada subplot
for i, ax in enumerate(axs.flat):
tienda = tiendas[i]
ax.plot(meses, df.loc[tienda], marker='o', linewidth=3, color=colores[i])
ax.set_title(f'Tienda {tienda}', fontsize=14, loc='left', fontweight='bold')
ax.set_xlabel('Mes', fontsize=12)
ax.set_ylabel('Ventas', fontsize=12)
ax.tick_params(axis='x', rotation=45, labelsize=10)
ax.tick_params(axis='y', labelsize=10)
ax.grid(True, linestyle='--', alpha=0.5) # cuadrícula ligera
Ajustar espacios
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.show()