Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Adding One More Line | Basics: Line Charts
Visualization in Python with matplotlib
course content

Course Content

Visualization in Python with matplotlib

Visualization in Python with matplotlib

1. Basics: Line Charts
2. Bar Charts
3. Scatter Plots

bookAdding One More Line

Quite good! That's a good visualization! Let's expand our chart with new data.

We may want to compare the emission levels by displaying several lines on a single chart. It can be easily done by calling the .plot() method of Axes object multiple times. For instance, if you call ax.plot() two times, you will get two lines on one chart. By default, the first line will be blue, the second one will be orange.

1234567891011121314151617181920
# Import the libraries import matplotlib.pyplot as plt import pandas as pd # Load the data data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/co2.csv', index_col = 0) # Filter the data ita = data.loc['Italy'] swe = data.loc['Sweden'] # Create Figure and Axes objects fig, ax = plt.subplots() # Initialize lines ax.plot(ita.index.astype(int), ita.values) ax.plot(swe.index.astype(int), swe.values) # Display the plot plt.show()
copy

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
some-alt