Python notes #09 # Basic plots with matplotlib

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.