Add Data to the Plot
Let's improve our plot by adding data for one more country.
Aufgabe
Swipe to start coding
Display the lines for the United States and Canada emission levels on a single chart. Follow the next steps:
- Create
Figure
andAxes
objects assigned to variablesfig
,ax
respectively. - Save within the
can
variable data forCanada
. - Use the same approach as for the
usa
data for building a new line for thecan
data.
Lösung
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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)
# Create Figure and Axes objects
fig, ax = plt.subplots()
# Save data for the US and Canada
usa = data.loc['United States']
can = data.loc['Canada']
# Initialize the plot
ax.plot(usa.index.astype(int), usa.values)
ax.plot(can.index.astype(int), can.values)
# Display the plot
plt.show()
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 5
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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)
# Create Figure and Axes objects
fig, ax = ___()
# Save data for the US and Canada
usa = data.loc['United States']
can = data.loc['___']
# Initialize the plot
ax.plot(usa.index.astype(int), usa.values)
ax.plot(___, ___)
# Display the plot
plt.show()
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen