import numpy as np
import matplotlib.pyplot as plt def is_outlier(points, threshold=3.5):
if len(points.shape) == 1:
points = points[:, None] # Find the median number of points
median = np.median(points, axis=0) diff = np.sum((points - median)**2, axis=-1)
diff = np.sqrt(diff)
MAD = np.median(diff) MZS = 0.6745 * diff / MAD return MZS > threshold # Create 100 random numbers
x = np.random.random(100) # The number of the histogram buckets
buckets = 50 # Add in a few outliers
x = np.r_[x, -49, 95, 100, -100] # The function 'is_outlier()' return a array of boolean
# If True, get the element; else pass the element
# For example:
# x = [1,2,3,4]
# y = x[array([False,True,True,False])]
# y is [2,3]
filtered = x[~is_outlier(x)] # Create a new figure
plt.figure() # Define the width of the figure
plt.subplot(211)
# Drawing histogram
# histogram(arr,bins,normed,facecolor,edgecolor,alpha,histtype)
plt.hist(x, buckets)
plt.xlabel('Raw') plt.subplot(212)
plt.hist(filtered, buckets)
plt.xlabel('Cleaned') # Show the figure
plt.show()

Python Data Visualization Cookbook 2.9.2的更多相关文章

  1. Python Data Visualization Cookbook 2.2.2

    import csv filename = 'ch02-data.csv' data = [] try: with open(filename) as f://用with语句将数据文件绑定到对象f r ...

  2. [Machine Learning with Python] Data Visualization by Matplotlib Library

    Before you can plot anything, you need to specify which backend Matplotlib should use. The simplest ...

  3. 7 Tools for Data Visualization in R, Python, and Julia

    7 Tools for Data Visualization in R, Python, and Julia Last week, some examples of creating visualiz ...

  4. 学习笔记之Introduction to Data Visualization with Python | DataCamp

    Introduction to Data Visualization with Python | DataCamp https://www.datacamp.com/courses/introduct ...

  5. Data Visualization – Banking Case Study Example (Part 1-6)

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  6. 学习笔记之Bokeh Data Visualization | DataCamp

    Bokeh Data Visualization | DataCamp https://www.datacamp.com/courses/interactive-data-visualization- ...

  7. 学习笔记之Data Visualization

    Data visualization - Wikipedia https://en.wikipedia.org/wiki/Data_visualization Data visualization o ...

  8. Data Visualization 课程 笔记1

    对数据可视化比较有兴趣,因此最近在看coursera上伊利诺伊大学香槟分校的数据可视化课程,做了一些笔记. 1. 定义 Data visualization is a high bandwidth c ...

  9. DATA VISUALIZATION – PART 2

    A Quick Overview of the ggplot2 Package in R While it will be important to focus on theory, I want t ...

随机推荐

  1. Day2:T1搜索 T2最小生成树

    T1:广搜+判断矩形 注:如何判断搜的是否为矩形: 在广搜的时候,记录下边界的坐标,然后枚举一遍过去,如果搜到"."就是牛群,否则就是房间 瞥了一眼ccy的做法,据说是floodf ...

  2. linux下使用kpartx挂载虚拟文件系统

    在linux中,如果映像文件(.img)含有分区表的话,那么用losetup这个程序来加载文件系统就有点力不从心了.因为losetup只能加载无分区的文件系统映像文件.不过有一个好东西配合losetu ...

  3. Rustlang语言逐行处理文件的基本方法

    文件操作 需求: 将文件中的内容按行读取出来,然后对改行的数据进行处理,最后将处理后的行数据存放到新的文件中. 使用RUST来处理的方法如下. 首先引入需要的标准库: use std::io::pre ...

  4. About Spring

    “Spring is the most popular application development framework for enterprise Java.”这是Spring官方首页上的第一句 ...

  5. Microsoft2013校园招聘笔试题

    Microsoft2013校园招聘笔试题 继续求拍砖!!!! 1. You are managing the database of a book publichser, you currently ...

  6. 行业介绍:车载DVD MID 导航用料一般包含国腾LVDS芯片GM8284C/GM8283

    车载DVD MID 导航用料一般包含国腾LVDS芯片 GM8284C/GM8283/替代SN75LVDS83,THC63LVDM83C , 音频ES7144/CS4344,  龙讯MHL HDMI芯片 ...

  7. transaction manager has disabled its support for remote/network transactions. 该伙伴事务管理器已经禁止了它对远程/网络事务

    最近再用SSIS做数据归档,里面用到了分布式事务.在开发阶段是在一台计算机上运行只要是启动分布式服务就没什么问题,可是昨天把它部署到uat的时候遇到问题,错误信息是: 最后找到解决方案: 确认&quo ...

  8. c++字符串连接方法大观

    c++字符串连接方法大观 抛砖引玉: springf(config_itemID[i],"ItemID%s_%d",i,i); 大家说说自己都用什么方法,个有什么利弊呢?

  9. Android开发(19)---常见dialog对话框的运用

    Dialog是android开发过程中最常用到的组件之一,Dialog的创立办法有两种: 一是直接new一个Dialog目标,然后调用Dialog目标的show和dismiss办法来操控对话框的显现和 ...

  10. 如何在网站中加入markdown

    在vue组件中加入markdown,模板使用的是webpack 我是这样做的: 因为是npm引入的,所以markdown是遵循CommonJS规范的,需要在webpack.base.conf.js里引 ...