源: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()

Python笔记 #09# Basic plots with matplotlib的更多相关文章

  1. Intermediate Python for Data Science learning 1 - Basic plots with matplotlib

    Basic plots with matplotlib from:https://campus.datacamp.com/courses/intermediate-python-for-data-sc ...

  2. python笔记09

    今日内容 三元运算 函数 内容详细 三元运算(三目运算) v = 前面 if 条件 else 后面 if 条件: v = '前面' else: v = '后面' # 让用户输入值,如果值是整数,则转换 ...

  3. 机器学习实战(Machine Learning in Action)学习笔记————09.利用PCA简化数据

    机器学习实战(Machine Learning in Action)学习笔记————09.利用PCA简化数据 关键字:PCA.主成分分析.降维作者:米仓山下时间:2018-11-15机器学习实战(Ma ...

  4. python笔记之常用模块用法分析

    python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...

  5. python笔记-1(import导入、time/datetime/random/os/sys模块)

    python笔记-6(import导入.time/datetime/random/os/sys模块)   一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...

  6. s21day25 python笔记

    s21day25 python笔记 正则表达式 1.定义 定义:正则表达式是一种规则匹配字符串的规则 re模块本身只是用来操作正则表达式的,和正则本身没关系 为什么要有正则表达式? 匹配字符串 一个人 ...

  7. Python笔记之不可不练

    如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...

  8. boost.python笔记

    boost.python笔记 标签: boost.python,python, C++ 简介 Boost.python是什么? 它是boost库的一部分,随boost一起安装,用来实现C++和Pyth ...

  9. 20.Python笔记之SqlAlchemy使用

    Date:2016-03-27 Title:20.Python笔记之SqlAlchemy使用 Tags:python Category:Python 作者:刘耀 博客:www.liuyao.me 一. ...

随机推荐

  1. django 自定模板标签的注册

    首先注册方法一般都是先实例化一个template.Library.如: from django import template register = template.Library() 1.注册自定 ...

  2. Intellij debug模式使用

    1.这里以一个web工程为例,点击图中按钮开始运行web工程. 2.设置断点 3.使用postman发送http请求 4.请求发送之后会自动跳到断点处,并且在断点之前会有数据结果显示 5.按F8 在 ...

  3. JavaIO详解

    很全面的内容:http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html

  4. Intel产品AMT本地及远程提权漏洞(CVE-2017-5689)复现 【转载自freebuf.com】

    零.绪论: 1.鸣谢freebuf的文章,主要是学习这个漏洞,文章地址: Intel产品AMT本地及远程提权漏洞(CVE-2017-5689)复现 2.在shadon上找了多个该漏洞尝试复现失败(评论 ...

  5. Testlink在CentOS、windows安装

    有幸在CentOS\windows上都安装过Teslink程序,总结一下.如下: 一.CentOS安装: 1.安装包需要: xampp xampp-linux-x64-5.6.3-0-installe ...

  6. java 中的String类型数据添加双引号

    转义符 \ 加上引号   \" <?xml version="1.0"encoding="GBK"?> String temp = &qu ...

  7. HOJ 2252 The Priest(动态规划)

    The Priest Source : 计算机学院第二届"光熙杯"程序设计大赛 Time limit : 3 sec Memory limit : 32 M Submitted : ...

  8. as modern frameworks have warmed people to the idea of using builder-type patterns and anonymous inner classes for such things

    mybatis – MyBatis 3 | SQL语句构建器 http://www.mybatis.org/mybatis-3/zh/statement-builders.html SqlBuilde ...

  9. AJAX.basic

    之前在项目中使用ajax都是通过jQuery的Ajax API来进行的,今天试了一下通过基本的JavaScript来进行ajax请求,将代码记录下来: jsp 页面 <%@ page pageE ...

  10. Tunnelblick 覆盖安装失败

    公司搬家, jira, sourceTree都链接不上了,发现是VPN断了的原因,需要重新链接VPN Tunnelblick坏掉了,覆盖安装总是提示安装失败,安装超时 nil,搜索一大堆文章, 看了这 ...