import pandas as pd
import matplotlib.pyplot as plt
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)
Crear figura 2x2
fig, axs = plt.subplots(2, 2, figsize=(14, 8))
Convertimos axs en una lista plana (para recorrerla fácil)
axs = axs.flatten()
Recorremos tiendas y posiciones al mismo tiempo
for i, tienda in enumerate(tiendas):
axs[i].plot(df.columns, df.loc[tienda])
axs[i].set_title(f'Tienda {tienda}')
axs[i].set_xlabel('Meses')
axs[i].set_ylabel('Ventas')
Título general
fig.suptitle('Variación de Ventas por Tienda - 2022', fontsize=16)
plt.tight_layout()
plt.subplots_adjust(top=0.90)
plt.show()