Preparación de figuras para compartirlas con los demás

Introducción a la visualización de datos con Matplotlib

Ariel Rokem

Data Scientist

Cambiar el estilo del gráfico

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"])
ax.set_xlabel("Time (months)")
ax.set_ylabel("Average temperature (Fahrenheit degrees)")
plt.show()

Introducción a la visualización de datos con Matplotlib

Elegir un estilo

plt.style.use("ggplot")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introducción a la visualización de datos con Matplotlib

Volver a los valores predeterminados

plt.style.use("default")
Introducción a la visualización de datos con Matplotlib

Los estilos disponibles

Introducción a la visualización de datos con Matplotlib

El estilo "bmh"

plt.style.use("bmh")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introducción a la visualización de datos con Matplotlib

Estilos Seaborn

plt.style.use("seaborn-colorblind")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Introducción a la visualización de datos con Matplotlib

Pautas para elegir el estilo de gráfico

  • Los fondos oscuros suelen ser menos visibles
  • Si el color es importante, puedes elegir opciones accesibles para personas daltónicas
    • "seaborn-colorblind" o "tableau-colorblind10"
  • Si crees que alguien querrá imprimir tu figura, utiliza menos tinta
  • Si se va a imprimir en blanco y negro, utiliza el estilo "grayscale"
Introducción a la visualización de datos con Matplotlib

¡Practica para elegir el estilo adecuado para ti!

Introducción a la visualización de datos con Matplotlib

Preparing Video For Download...