Search⌘ K

Line and Bar Plots

Explore how to create and customize line and bar plots using pandas for DataFrames. Understand how to manipulate data for clearer visualizations, including highlighting specific data lines and using horizontal bar plots to improve readability.

We'll cover the following...

Line Plots

The DataFrame has a plot attribute that we can use to plot. Line plots are easy to create. Remember that pandas will plot the index in the x-axis, and each column will be its own line. Below is a default plot. It’s a little hard to process, but along the x-axis are the presidents (from the first to the last), and each line represents what happens to the score from president to president:

Python 3.8
pres.plot().legend(bbox_to_anchor=(1,1))

Let’s make another line plot that is more involved. Each line will track the scores for a single president. ...