Preparing your figures to share with others

Introduction to Data Visualization with 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()

Introduction to Data Visualization with 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()

Introduction to Data Visualization with Matplotlib

Back to the default

plt.style.use("default")
Introduction to Data Visualization with Matplotlib

The available styles

Introduction to Data Visualization with 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()

Introduction to Data Visualization with 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()

Introduction to Data Visualization with 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
Introduction to Data Visualization with Matplotlib

Practice choosing the right style for you!

Introduction to Data Visualization with Matplotlib

Preparing Video For Download...