Preparing your figures to share with others

Introduzione alla visualizzazione dei dati con Matplotlib

Ariel Rokem

Data Scientist

Changing plot style

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()

Introduzione alla visualizzazione dei dati con Matplotlib

Choosing a style

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()

Introduzione alla visualizzazione dei dati con Matplotlib

Back to the default

plt.style.use("default")
Introduzione alla visualizzazione dei dati con Matplotlib

The available styles

Introduzione alla visualizzazione dei dati con Matplotlib

The "bmh" style

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()

Introduzione alla visualizzazione dei dati con Matplotlib

Seaborn styles

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()

Introduzione alla visualizzazione dei dati con Matplotlib

Guidelines for choosing plotting style

  • Dark backgrounds are usually less visible
  • If color is important, consider choosing colorblind-friendly options
    • "seaborn-colorblind" or "tableau-colorblind10"
  • If you think that someone will want to print your figure, use less ink
  • If it will be printed in black-and-white, use the "grayscale" style
Introduzione alla visualizzazione dei dati con Matplotlib

Practice choosing the right style for you!

Introduzione alla visualizzazione dei dati con Matplotlib

Preparing Video For Download...