Histograms

from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib?ex=7

  • Build a histogram (1)

life_exp, the list containing data on the life expectancy for different countries in 2007, is available in your Python shell.

To see how life expectancy in different countries is distributed, let's create a histogram of life_exp.

# import matplotlib.pyplot

import matplotlib.pyplot as plt

# Create histogram of life_exp data. Do not specify the number of bins; Python will set the number of bins to 10 by default for you.

plt.hist(life_exp)

# Display histogram
plt.show()

  • Build a histogram (2): bins

To control the number of bins to divide your data in, you can set the bins argument.

# Build histogram with 5 bins
plt.hist(life_exp, bins = 5)

# Show and clean up plot
plt.show()
plt.clf()

# Build histogram with 20 bins
plt.hist(life_exp,bins = 20)

# Show and clean up again
plt.show()
plt.clf()

  • Build a histogram (3): compare

Let's do a similar comparison. life_exp contains life expectancy data for different countries in 2007. You also have access to a second list now, life_exp1950, containing similar data for 1950. Can you make a histogram for both datasets?

# Histogram of life_exp, 15 bins
import matplotlib.pyplot as plt
plt.hist(life_exp, bins = 15)

# Show and clear plot
plt.show()
plt.clf()

# Histogram of life_exp1950, 15 bins
plt.hist(life_exp1950, bins = 15)

# Show and clear plot again
plt.show()
plt.clf()

  • Choose the right plot (1)

You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a particular distribution. Which plot do you use?

->Histogram

  • Choose the right plot (2)

You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?

->Scatter plot

Intermediate Python for Data Science learning 2 - Histograms的更多相关文章

  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. Intermediate Python for Data Science learning 3 - Customization

    Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...

  3. 学习笔记之Intermediate Python for Data Science | DataCamp

    Intermediate Python for Data Science | DataCamp https://www.datacamp.com/courses/intermediate-python ...

  4. Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics

    NumPy: Basic Statistics from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/ch ...

  5. Intro to Python for Data Science Learning 7 - 2D NumPy Arrays

    2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...

  6. Intro to Python for Data Science Learning 5 - Packages

    Packages From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functio ...

  7. Intro to Python for Data Science Learning 2 - List

    List from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-2-python-list ...

  8. Intro to Python for Data Science Learning 6 - NumPy

    NumPy From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=1 ...

  9. Intro to Python for Data Science Learning 4 - Methods

    Methods From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-function ...

随机推荐

  1. C语言位操作--判断整数是否为2的幂

    unsigned int v; // 判断v是否为2的幂 bool f; // f为判断的结果 f = (v & (v - 1)) == 0; // 结果为0表示不是2 的幂 // 改变表示方 ...

  2. C# 多线程ManualResetEvent、等待所有线程

    需求:成员A可能有几十个,我需要更新所有的A,然后根据A的数据,去更新成员B. 解决方案:思路是想通过多线程更新所有的A,然后通过等待线程来确定所有的A是否都更新完,最后更新B. Member B = ...

  3. [Windows] 使用SC 命令管理与配置服务

    sc config wuauserv start= demand sc config wuauserv start= disabled

  4. ssh连接超时时间(ssh timeout)的设置方法

    问题:当某台远程主机宕机时,ssh远程过去会耗费很多的时间去连接,结果还是会失败. 这个时候可以设置超时时间 ssh -o ConnectTimeout= 192.168.0.10

  5. Linux查看磁盘目录内存空间使用情况

    du 显示每个文件和目录的磁盘使用空间 命令参数 -c或--total  除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和. -s或--summarize  仅显示总计,只列出最后加总的 ...

  6. vue中打包生成可配置文件以便修改接口地址

    vue打包上传到服务器之后,如果数据接口域名发生变化,需要手动修改接口地址,在发布的时候也麻烦,于是.. 在打包之后如果有一个json配置文件以便修改那不是方便很多 在网上找了一些方法貌似都是异步请求 ...

  7. Saltstack之SSH

    salt-minion也可以不安装通过在master安装salt-ssh 1,安装 yum -y install salt-ssh 2,配置salt的花名册 vim /etc/salt/roster ...

  8. Nginx 日志 worker_connections are not enough while connecting to upstream

    记一次,排查错误所遇到的问题,和学习到的内容. 上周五,刚上线的项目出现了503 ,查看日志发现如下内容: System.Exception: Request api/blogpost/zzkDocs ...

  9. SQL Fundamentals || DCL(Data Control Language) || 角色ROLES

    SQL Fundamentals || Oracle SQL语言 语句 解释 Create user Creates a user(usually performed by a DBA) Grant ...

  10. socket 中午吃的啥 socket 并发服务器 fork

    http://www.cnblogs.com/thinksasa/archive/2013/02/26/2934206.html zh.wikipedia.org/wiki/網路插座 在作業系統中,通 ...