zoukankan      html  css  js  c++  java
  • Python笔记 #09# Basic plots with matplotlib

    源:DataCamp

    气泡的大小表示人口的多少,横坐标表示人均GDP(美元),纵坐标表示预期寿命。-- 作者:Hans Rosling

    Python 中有许许多多用于可视化的包,而 matplotlib 是它们的源头。

    我们需要用到的是它的子包 pyplot ,通常它被简写成 plt 导入

    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, pop 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 plot
    plt.show()

     

    2、Scatter Plot 

    When you have 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 two variables, for example, the scatter plot is the better choice. Below is an example of how 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 logarithmic scale
    plt.xscale('log')
    
    # Show plot
    plt.show()

    # Import package
    import matplotlib.pyplot as plt
    
    # Build Scatter plot
    plt.scatter(pop, life_exp)
    
    # Show plot
    plt.show()
  • 相关阅读:
    【KVM系列 virt-v2v】virt-v2v过程中的报错
    大机与超级计算机的区别
    多路径 on linux
    ansible 管控 windows
    Linux启动盘
    RHCA 环境命令
    Xshell 4 连接 Ubuntu/Kali 报错 "找不到匹配的key exchange算法"
    security group & ACL
    windows powercfg
    OKD
  • 原文地址:https://www.cnblogs.com/xkxf/p/8280533.html
Copyright © 2011-2022 走看看