Source: Datacamp
The size of the bubbles indicates how much the population is, and the horizontal axis represents GDP per capita (USD), and the ordinate represents life expectancy. --Hans Rosling
Python has many packages for visualization, and matplotlib is the source of them.
What we need to use is its sub-package Pyplot , which is usually abbreviated as a plt import
1. Line plot
# Print The last item from year and pop Print (year[-1]) Print (pop[-1]) # Import Matplotlib.pyplot as Plt Import Matplotlib.pyplot as Plt # Make a line plot:year on the X-axis, pops on the y-axis Plt.plot (year, pop) # Display the plot with Plt.show ()plt.show ()
\
# Print The last item of Gdp_cap and Life_exp Print (gdp_cap[-1]) Print (life_exp[-1]) # Make a line plot, Gdp_cap on the x-axis, life_exp on the y-axis Plt.plot (Gdp_cap, Life_exp) # Display the plotplt.show ()
2. Scatter Plot
When you had a time scale along the horizontal axis, the line plot is your friend. But in many other cases, when you're trying to assess if there ' s a correlation between-variables, for example, the SCA Tter plot is the better choice. Below is an example of what to build a scatter plot.
# Change the line plot below to a scatter plot Plt.scatter (Gdp_cap, Life_exp) # Put The x-axis on a logarithmicscale plt.xscale ('log')# Show plotplt.show ()
\
# Import Package Import Matplotlib.pyplot as Plt # Build Scatter plot plt.scatter (pop, life_exp) # Show plotplt.show ()
Python notes #09 # Basic plots with matplotlib