14 Visualization

 

This chapter covers

  • Installing the Matplotlib library for data visualization
  • Rendering graphs and charts with pandas and Matplotlib
  • Applying color templates to visualizations

Text-based DataFrame summaries are helpful, but many times, a story can best be told by a visualization. A line chart can quickly communicate a trend over time; a bar graph can distinctly identify unique categories and their counts; a pie chart can represent proportions in an easily digestible manner, and so on. Fortunately, pandas seamlessly integrates with many popular Python data visualization libraries, including Matplotlib, seaborn, and ggplot. In this chapter, we’ll learn how to use Matplotlib to render dynamic charts from our Series and DataFrames. I hope that these visualizations help you add that little spark to your data presentations.

14.1 Installing matplotlib

By default, pandas relies on the open source Matplotlib package to render charts and graphs. Let’s install it in our Anaconda environment.

Begin by launching the Terminal (macOS) or Anaconda Prompt (Windows) application for your operating system. The default Anaconda environment, base, should be listed in parentheses to the left. base is the currently active environment.

When we installed Anaconda (see appendix A), we created an environment called pandas_in_action. Let’s execute the conda activate command to activate it. If you chose a different environment name, replace pandas_in_action with that name, as follows:

14.2 Line charts

14.3 Bar graphs

14.4 Pie charts

Summary