文章目录

  • 散点图案例: 北京2016年3月 和10月 最高气温, 找出气温随时间变化的规律
  • 条形图案例1: 2017年内地电影票房前20的电影(列表a)和电影票房数据(列表b)
  • 条形图案例2: 列表a中电影分别在2017-09-14(b_14), 2017-09-15(b_15), 2017-09-16(b_16)三天的票房
  • 直方图案例1:获取了250部电影的时长(列表a中),希望统计出这些电影时长的分布状态
  • 直方图案例2:美国2004年人口普查发现有124 million的人在离家相对较远的地方工作,他们从家到上班地点所需要的时间,通过抽样统计.

散点图案例: 北京2016年3月 和10月 最高气温, 找出气温随时间变化的规律

y3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
y10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]

from matplotlib import pyplot as plt
from matplotlib import font_managermy_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')
y3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
y10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]x3 = range(1,32)
x10 = range(51,82)plt.figure(figsize=(20,8),dpi=80)
plt.scatter(x3,y3,label = '3月份')
plt.scatter(x10,y10,label = '10月份')_x = list(x3)+list(x10)
_xtick_labels = ['3月{}日'.format(i) for i in x3]
_xtick_labels += ['10月{}日'.format(i-50) for i in x10]
plt.xticks(_x[::3], _xtick_labels[::3], fontproperties = my_font, rotation=45)plt.legend(loc='upper left',prop = my_font)plt.xlabel('时间',fontproperties = my_font)
plt.ylabel('温度',fontproperties = my_font)
plt.title('标题',fontproperties = my_font)plt.savefig('day2-1.png')
plt.show()

条形图案例1: 2017年内地电影票房前20的电影(列表a)和电影票房数据(列表b)

a = [“战狼2”,“速度与激情8”,“功夫瑜伽”,“西游伏妖篇”,“变形金刚5:最后的骑士”,“摔跤吧!爸爸”,“加勒比海盗5:死无对证”,“金刚:骷髅岛”,“极限特工:终极回归”,“生化危机6:终章”,“乘风破浪”,“神偷奶爸3”,“智取威虎山”,“大闹天竺”,“金刚狼3:殊死一战”,“蜘蛛侠:英雄归来”,“悟空传”,“银河护卫队2”,“情圣”,“新木乃伊”,]

b=[56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]
单位:亿

竖版:

from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')
x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:\n最后的骑士","摔跤吧!爸爸","加勒比海盗5:\n死无对证","金刚:骷髅岛","极限特工:\n终极回归","生化危机6:\n终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:\n殊死一战","蜘蛛侠:\n英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]
y = [56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]#设置图形大小plt.figure(figsize=(20,15),dpi=80)plt.bar(range(len(x)),y,width=0.3)plt.xticks(range(len(x)),x,fontproperties=my_font,rotation=90)plt.savefig('day2-2.png')plt.show()

横版:

from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')
x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:\n最后的骑士","摔跤吧!爸爸","加勒比海盗5:\n死无对证","金刚:骷髅岛","极限特工:\n终极回归","生化危机6:\n终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:\n殊死一战","蜘蛛侠:\n英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]
y = [56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]#设置图形大小plt.figure(figsize=(30,8),dpi=80)plt.barh(range(len(x)),y,height=0.3,color='orange')plt.yticks(range(len(x)),x,fontproperties=my_font,rotation=0)plt.grid(alpha=0.3)
plt.savefig('day2-3.png')plt.show()

条形图案例2: 列表a中电影分别在2017-09-14(b_14), 2017-09-15(b_15), 2017-09-16(b_16)三天的票房

a = [“猩球崛起3:终极之战”,“敦刻尔克”,“蜘蛛侠:英雄归来”,“战狼2”]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]

from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]#设置图形大小plt.figure(figsize=(20,8),dpi=80)bar_width = 0.2
x_14 = list(range(len(a)))
x_15 = [i+bar_width for i in x_14]
x_16 = [i+bar_width*2 for i in x_14]plt.bar(range(len(a)),b_14,width=0.2,label='9月14日',color='green')plt.bar(x_15,b_15,width=0.2,label='9月15日',color='blue')plt.bar(x_16,b_16,width=0.2,label='9月16日',color='orange')#设置图例
plt.legend(prop=my_font)#设置x轴刻度
plt.xticks(x_15,a,fontproperties=my_font,rotation=0)plt.grid(alpha=0.3)plt.savefig('day2-4.png')plt.show()

直方图案例1:获取了250部电影的时长(列表a中),希望统计出这些电影时长的分布状态

a=[131, 98, 125, 131, 124, 139, 131, 117, 128, 108, 135, 138, 131, 102, 107, 114, 119, 128, 121, 142, 127, 130, 124, 101, 110, 116, 117, 110, 128, 128, 115, 99, 136, 126, 134, 95, 138, 117, 111,78, 132, 124, 113, 150, 110, 117, 86, 95, 144, 105, 126, 130,126, 130, 126, 116, 123, 106, 112, 138, 123, 86, 101, 99, 136,123, 117, 119, 105, 137, 123, 128, 125, 104, 109, 134, 125, 127,105, 120, 107, 129, 116, 108, 132, 103, 136, 118, 102, 120, 114,105, 115, 132, 145, 119, 121, 112, 139, 125, 138, 109, 132, 134,156, 106, 117, 127, 144, 139, 139, 119, 140, 83, 110, 102,123,107, 143, 115, 136, 118, 139, 123, 112, 118, 125, 109, 119, 133,112, 114, 122, 109, 106, 123, 116, 131, 127, 115, 118, 112, 135,115, 146, 137, 116, 103, 144, 83, 123, 111, 110, 111, 100, 154,136, 100, 118, 119, 133, 134, 106, 129, 126, 110, 111, 109, 141,120, 117, 106, 149, 122, 122, 110, 118, 127, 121, 114, 125, 126,114, 140, 103, 130, 141, 117, 106, 114, 121, 114, 133, 137, 92,121, 112, 146, 97, 137, 105, 98, 117, 112, 81, 97, 139, 113,134, 106, 144, 110, 137, 137, 111, 104, 117, 100, 111, 101, 110,105, 129, 137, 112, 120, 113, 133, 112, 83, 94, 146, 133, 101,131, 116, 111, 84, 137, 115, 122, 106, 144, 109, 123, 116, 111,111, 133, 150]

from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')a=[131,  98, 125, 131, 124, 139, 131, 117, 128, 108, 135, 138, 131, 102, 107, 114, 119, 128, 121, 142, 127, 130, 124, 101, 110, 116, 117, 110, 128, 128, 115,  99, 136, 126, 134,  95, 138, 117, 111,78, 132, 124, 113, 150, 110, 117,  86,  95, 144, 105, 126, 130,126, 130, 126, 116, 123, 106, 112, 138, 123,  86, 101,  99, 136,123, 117, 119, 105, 137, 123, 128, 125, 104, 109, 134, 125, 127,105, 120, 107, 129, 116, 108, 132, 103, 136, 118, 102, 120, 114,105, 115, 132, 145, 119, 121, 112, 139, 125, 138, 109, 132, 134,156, 106, 117, 127, 144, 139, 139, 119, 140,  83, 110, 102,123,107, 143, 115, 136, 118, 139, 123, 112, 118, 125, 109, 119, 133,112, 114, 122, 109, 106, 123, 116, 131, 127, 115, 118, 112, 135,115, 146, 137, 116, 103, 144,  83, 123, 111, 110, 111, 100, 154,136, 100, 118, 119, 133, 134, 106, 129, 126, 110, 111, 109, 141,120, 117, 106, 149, 122, 122, 110, 118, 127, 121, 114, 125, 126,114, 140, 103, 130, 141, 117, 106, 114, 121, 114, 133, 137,  92,121, 112, 146,  97, 137, 105,  98, 117, 112,  81,  97, 139, 113,134, 106, 144, 110, 137, 137, 111, 104, 117, 100, 111, 101, 110,105, 129, 137, 112, 120, 113, 133, 112,  83,  94, 146, 133, 101,131, 116, 111,  84, 137, 115, 122, 106, 144, 109, 123, 116, 111,111, 133, 150]#计算组数d = 3  #组距
num_bins = (max(a)-min(a))//dplt.figure(figsize=(20,8),dpi=80)
plt.hist(a,num_bins,density=1)#设置x轴刻度plt.xticks(range(min(a),max(a)+d,d))plt.grid(alpha=0.2)
plt.savefig('day2-5.png')
plt.show()

直方图案例2:美国2004年人口普查发现有124 million的人在离家相对较远的地方工作,他们从家到上班地点所需要的时间,通过抽样统计.

interval = [0,5,10,15,20,25,30,35,40,45,60,90] #
width = [5,5,5,5,5,5,5,5,5,15,30,60] #组距
quantity = [836,2737,3723,3926,3596,1438,3273,642,824,613,215,47]

from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc')interval = [0,5,10,15,20,25,30,35,40,45,60,90] #时间段
width = [5,5,5,5,5,5,5,5,5,15,30,60]  #组距
quantity = [836,2737,3723,3926,3596,1438,3273,642,824,613,215,47] #人数plt.figure(figsize=(20,8),dpi=80)plt.bar(range(len(quantity)),quantity,width=1)print(len(interval),len(width),len(quantity))#设置x轴刻度_x = [i-0.5 for i in range(13)]
_xtick_labels = interval+[150]
plt.xticks(_x, _xtick_labels)plt.grid()
plt.savefig('day2-6.png')
plt.show()

Data Analysis - Day2 - Matplotlib 案例相关推荐

  1. python进行探索性数据分析EDA(Exploratory Data Analysis)分析

    python进行探索性数据分析EDA(Exploratory Data Analysis)分析 show holy respect to python community, for there ded ...

  2. 【Python-ML】探索式数据分析EDA(Exploratory Data Analysis)

    # -*- coding: utf-8 -*- ''' Created on 2018年1月24日 @author: Jason.F @summary: 有监督回归学习-探索式数据分析(EDA,Exp ...

  3. 数据分析---《Python for Data Analysis》学习笔记【04】

    <Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...

  4. IBM Machine Learning学习笔记(一)——Exploratory Data Analysis for Machine Learning

    数据的探索性分析 1. 读入数据 (1)csv文件读取 (2)json文件读取 (3)SQL数据库读取 (4)Not-only SQL (NoSQL)读取 (5)从网络中获取 2. 数据清洗 (1)缺 ...

  5. 《利用Python进行数据分析: Python for Data Analysis 》学习随笔

    NoteBook of <Data Analysis with Python> 3.IPython基础 Tab自动补齐 变量名 变量方法 路径 解释 ?解释, ??显示函数源码 ?搜索命名 ...

  6. python学习笔记(Data Analysis)

    Python for Data Analysis numpy基础 嗯 调整了一些顺序 1 ndarray(n维数组) 导入数据.基本运算和数组生成 import numpy as np #矢量化 将数 ...

  7. 【CookBook pandas】学习笔记第五章 Exploratory Data Analysis

    dive more into - 深入讨论 exploratory data analysis , the process of sifting through the data and trying ...

  8. Hi-C data analysis tools and papers

    Hi-C data analysis tools and papers 全文链接如下: https://github.com/mdozmorov/HiC_tools Tools are sorted ...

  9. R语言统计入门课程推荐——生物科学中的数据分析Data Analysis for the Life Sciences

    Data Analysis for the Life Sciences是哈佛大学PH525x系列课程--生物医学中的数据分析(PH525x series - Biomedical Data Scien ...

最新文章

  1. 技巧.自己学会取名字,学会欣赏
  2. 【CSS】CSS前期回顾(2)
  3. Android 编译系统分析(一)
  4. Objective-C中的instancetype和id关键字
  5. ubuntu下Rhythmbox音乐播放器乱码的解决方案
  6. 视觉中国网站部分恢复上线? 官方回应:并没有
  7. ubuntu查看cpu温度
  8. Impossible WHERE noticed after reading const tables
  9. teamview 局域网内使用
  10. Java之自动装箱与自动拆箱
  11. DELL笔记本插入耳机没反应
  12. 安装google扩展
  13. 程序员的自我修养——SQL语言及MySQL数据库
  14. 扫地机器人扫水泥地板有用吗_哪位知道扫地机器人水泥地可以使用吗
  15. 关于计算机优点缺点的英语作文,关于网络优缺点的英语作文(精选3篇)
  16. Android App安全监测隐私权限工具及自测
  17. matlab车牌识别字符切割,车牌识别字符分割问题
  18. 2022年全球与中国数字万用表市场现状及未来发展趋势
  19. Unity之手机重力感应
  20. 计算机控制系统国家精品课程,国家精品课程《计算机控制系统》建设与实践.ppt...

热门文章

  1. PHP输出1-20之间的奇数,php – MySQL查询仅输出奇数行
  2. 郑州大学“战疫杯”大学生程序设计在线邀请赛(2)(C++题解+详细思路)2022年5月10日
  3. [Nginx]Ngnix基础
  4. 如何在 Windows 中更改桌面位置
  5. 【霍尔效应传感器模块与 Arduino】
  6. 读《公正该如何做才好》
  7. Educational Codeforces Round 86 (Rated for Div. 2) Apr/26/2020 22:35UTC+8
  8. CSDN资源获取下载积分规则
  9. 2020中国上市公司品牌价值榜20强发布
  10. Android TimeoutException治理