Line plot (3)
Now that you've built your first line plot, let's start working on the data that professor Hans Rosling used to build his beautiful bubble chart. It was collected in 2007. Two lists are available for you:
life_expwhich contains the life expectancy for each country andgdp_cap, which contains the GDP per capita (i.e. per person) for each country expressed in US Dollars.
GDP stands for Gross Domestic Product. It basically represents the size of the economy of a country. Divide this by the population and you get the GDP per capita.
matplotlib.pyplot is already imported as plt, so you can get started straight away.
Diese Übung ist Teil des Kurses
Intermediate Python
Anleitung zur Übung
- Print the last item from both the list
gdp_cap, and the listlife_exp; it is information about Zimbabwe. - Build a line chart, with
gdp_capon the x-axis, andlife_expon the y-axis. Does it make sense to plot this data on a line plot? - Don't forget to finish off with a
plt.show()command, to actually display the plot.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Print the last item of gdp_cap and life_exp
# Make a line plot, gdp_cap on the x-axis, life_exp on the y-axis
# Display the plot