Saltar al contenido

# graficos-con-python

Gráficos con Python

Volver a la portada del curso
Video IA

Comparación entre Matplotlib y Plotly

Sección 5 · Proyecto Final y Comparaciones

En este video

  • Haces el mismo gráfico en Matplotlib con subplots, plot y legend, y obtienes una imagen estática
  • Lo repites en Plotly con line y ves que el código es más corto y el resultado interactivo
  • Aplicas la regla práctica: Matplotlib para informes, PDF y presentaciones; Plotly para navegador, tableros y notebooks
  • Recuerdas que Seaborn ahorra código en análisis estadísticos sobre Matplotlib
estatico.py
import matplotlib.pyplot as plt

meses = [1, 2, 3, 4, 5, 6]
fig, ax = plt.subplots()
ax.plot(meses, [10, 12, 15, 14, 18, 21],
        marker="o", label="Norte")
ax.plot(meses, [8, 9, 11, 13, 12, 15],
        marker="o", label="Sur")
ax.legend()
plt.show()
interactivo.py
import pandas as pd
import plotly.express as px

df = pd.DataFrame({
    "mes": [1, 2, 3, 4, 5, 6] * 2,
    "ventas": [10, 12, 15, 14, 18, 21,
               8, 9, 11, 13, 12, 15],
    "region": ["Norte"] * 6 + ["Sur"] * 6})
fig = px.line(df, x="mes", y="ventas",
              color="region", markers=True)
fig.show()