Desafío 1 – Facturamiento por región en 2023
import matplotlib.pyplot as plt
import seaborn as sns
Cálculo de facturación por región
df['facturacion'] = (df['valor_unitario'] * df['cantidad']) + df['costo_envio']
facturacion_region = df.groupby('region')['facturacion'].sum().sort_values(ascending=False)
Visual
fig, ax = plt.subplots(figsize=(16, 9))
fig.patch.set_facecolor(GRIS_1)
ax.set_facecolor(GRIS_1)
Barras
sns.barplot(x=facturacion_region.index,
y=facturacion_region.values / 1_000_000, # en millones
color=AQUA_1, ax=ax)
Títulos y etiquetas
ax.set_title('Facturación por Región en 2023', fontsize=18, color=GRIS_5, weight='bold')
ax.set_xlabel('Región', fontsize=12, color=AZUL_1)
ax.set_ylabel('Facturación (Millones)', fontsize=12, color=AZUL_1)
ax.tick_params(axis='x', colors=AZUL_1, labelsize=12)
ax.tick_params(axis='y', colors=AZUL_1, labelsize=12)
Mostrar valores en las barras
for p in ax.patches:
ax.annotate(f"{p.get_height():.1f}",
(p.get_x() + p.get_width() / 2, p.get_height()),
ha='center', va='bottom', fontsize=12, color=AZUL_1)
Quitar bordes
sns.despine(left=True, bottom=True)
plt.tight_layout()
plt.show()
Desafío 2 – Proporción de personas pre-registradas en Zoop Pay
Conteo de pre-registros
pre_registros = df['zoop_pay_preregistro'].value_counts()
Configuración de colores por categoría
colores = [AZUL_1 if label == 'Sí' else GRIS_3 for label in pre_registros.index]
Gráfico
fig, ax = plt.subplots(figsize=(6, 6))
fig.patch.set_facecolor(GRIS_1)
ax.set_facecolor(GRIS_1)
wedges, texts, autotexts = ax.pie(
pre_registros,
labels=pre_registros.index,
labeldistance=0.8,
colors=colores,
autopct='%1.1f%%',
pctdistance=0.8,
startangle=90,
wedgeprops={'width': 0.4}
)
Estilos de etiquetas
for text, color in zip(texts, colores):
text.set_color(color)
text.set_fontsize(12)
Estilos de porcentajes
for autotext in autotexts:
autotext.set_color('white')
autotext.set_fontsize(12)
autotext.set_fontweight('bold')
ax.set_title('Proporción de Clientes Pre-registrados en Zoop Pay',
fontsize=18, color=GRIS_5, weight='bold')
plt.tight_layout()
plt.show()