2.3 What is Matplotlib? And What is Seaborn?
The visualization examples used throughout this chapter are primarily built using two Python libraries: matplotlib and seaborn.
The matplotlib homepage notes that “Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.”3 Matplotlib enables users to generate many types of visualizations, while also retaining the ability to customize these visualizations’ appearance.
By convention, matplotlib.pyplot is aliased as plt.
The seaborn library is a newer, higher-level4 library, and is built on top of matplotlib. Since Seaborn directly handles Python’s dataframe structure, it enables a user to generate visualizations with fewer lines of code than would be required with matplotlib. Matplotlib is a bit less user-friendly, but offers the user more options for adjusting the plots’ appearance. Thankfully, these libraries are highly interoperable! Even a die-hard seaborn fan will still encounter scenarios in which the matplotlib customization capability comes in handy.
By convention, seaborn is aliased as sns. This is an homage to its namesake, as the library was named for Samuel Norman Seaborn, a fictional character on the television show “The West Wing.”
Throughout the rest of this chapter, you will see examples of visualizations built with these two popular Python libraries. To make the code work, you should be sure to include these two statements in your script:
import seaborn as sns
import matplotlib.pyplot as plt
4 In computing, the term “high level” refers to an option that is less technically complex for the user. In a higher-level system, more features and requirements are abstracted away from the user; in a lower-level system, the user can be said to be “closer to the machine.”