源: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. MySQL 分组后取每组前N条数据

    与oracle的 rownumber() over(partition by xxx  order by xxx )语句类似,即:对表分组后排序 创建测试emp表 1 2 3 4 5 6 7 8 9 ...

  2. poj_3436 网络最大流

    题目大意 生产电脑的工厂将一台电脑分成P个部件来进行流水线生产组装,有N个生产车间,每个车间可以将一个半成品电脑添加某些部件,使之成为另一个半成品电脑或者成为一台完好的电脑,且每个车间有一个效率,即在 ...

  3. 【Linux系列】find命令使用

    Linux下find命令在目录结构中搜素文件,病执行制定的操作. 一.命令格式 find pathname -options[-print -exec -ok] 二.命令功能 用于在文件树种查找文件, ...

  4. centos6.8上安装paramiko

    author : headsen  chen date: 2018-10-07   17:06:07 # 安装gcc,python-devel yum -y install python-devel ...

  5. SSH配置优化和慢的解决方法

    author: headsen chen date: 2018-08-18  00:28:37 ssh配置优化 vim  /etc/ssh/sshd_config 1,修改root端口 2,不允许ro ...

  6. Windows Phone 页面切换动画

    1.首先引用Microsoft.Phone.Toolkit 2.将App.xaml.cs 中的 RootFrame = new PhoneApplicationFrame(); 改成RootFrame ...

  7. mysql字符串根据指定字符分割

    1.分割函数:SUBSTRING_INDEX('浙江温州-中国电信','-','1') 2.用例(筛选'-'前至少4个汉字的数据) a.数据分布 b.筛选sql select t.mobile_num ...

  8. 微信小程序 --- 动画

    动画的基本使用: 旋转动画 缩放动画 偏移动画 倾斜动画 矩阵动画 动画API:wx.createAnimation(object) 示例:创建一个点击的动画 <view class=" ...

  9. pandas将字段中的字符类型转化为时间类型,并设置为索引

    假设目前已经引入了 pandas,同时也拥有 pandas 的 DataFrame 类型数据. import pandas as pd 数据集如下 df.head(3) date open close ...

  10. Jenkins中maven的作用--构建项目(三)

    本文主要根据Jenkins上的日志来继续说明构建项目的过程,上文我们已经讲到构建一个测试环境或单独终端的过程,详情可以了解上篇文章 一.背景介绍 首先看下SVN代码的仓库的结构: 代码仓库里有一个文件 ...