源: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. 虚拟机怎么设置u盘启动

    方法/步骤   1 运行你安装的虚拟机 步骤阅读 2 点击绿色的按钮,把你的虚拟机下面的系统启动. 步骤阅读 3 让你的虚拟系统处于可以按“Ctrl+Alt+Insert”重启的界面.比如我让虚拟系统 ...

  2. ASP.NET 4.0尚未在Web服务器注册 解决

    http://www.cnblogs.com/lvxiouzi/p/3511446.html 安装asp.net 4.0.30319.0版本 命令: %windir%\Microsoft.NET\Fr ...

  3. JS 保存表单默认值 为空时自动填充默认值

    var inputArray = document.getElementsByTagName("input"); var strArray = []; ; i < input ...

  4. LeetCode——Peeking Iterator

    Description: Given an Iterator class interface with methods: next() and hasNext(), design and implem ...

  5. CentOS下安装cvechecker并进行主机基线安全检查

    一.cvechecker的安装 1.首先下载cvechecker并解压该文件: cd /home/username mkdir cve wget https://raw.githubuserconte ...

  6. 【BZOJ4418】[Shoi2013]扇形面积并 扫描线+线段树

    [BZOJ4418][Shoi2013]扇形面积并 Description 给定N个同心的扇形,求有多少面积,被至少K个扇形所覆盖. Input 第一行是三个整数n,m,k.n代表同心扇形的个数,m用 ...

  7. 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树

    [BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...

  8. Unity3D 笔记二 3D模型基础

    一.3D模型基础 1.Hierarchy 显示的是界面上的游戏对象(GameObject),每个游戏对象都有.至少要有一个Camera,点击Camera就可以在Preview中看到摄像机的视角画面.每 ...

  9. Mac OS X运行程序出现bad interpreter: operation not permitted的解决方案

    最近想在我的mac笔记本上安装gvim,从官网上下载了程序后竟然非常诡异的双击无法打开,命令行执行时系统报错: /bin/sh bad interpreter operation not permit ...

  10. github团队协作教程

    跟着笔者魔鬼般的步伐,我们一起来瞅瞅一个团队协作的任务如何进行版本管理吧~ 要跟上哦~ =============================================== 首先我们先来看下 ...