码迷,mamicode.com
首页 > 编程语言 > 详细

python3绘图示例1(基于matplotlib)

时间:2018-12-15 22:54:52      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:otl   print   ring   2.0   json   points   turn   .sh   figure   

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
import json
from decimal import Decimal


# 保留浮点类型
jstring=‘{"name":"pro","price":12.05}‘
str=json.loads(jstring,parse_float=Decimal)
print(str)

# 柱状图
def is_outlier(points,threshold=3.5):
if len(points.shape)==1:
points=points[:,None]

median=np.median(points,axis=0)
diff=np.sum((points-median)**2,axis=-1)
diff=np.sqrt(diff)
med_abs_deviation=np.median(diff)

modified_z_score=0.6745*diff/med_abs_deviation
return modified_z_score > threshold


x=np.random.random(10)
buckets=50
np.r_[x,-49,95,100,-100]
fitered=x[~is_outlier(x)]

plt.figure()

plt.subplot(211)
plt.hist(x,buckets)
plt.xlabel(‘Raw‘)

plt.subplot(212)
plt.hist(fitered,buckets)
plt.xlabel(‘Cleaned‘)

plt.show()


python3绘图示例1(基于matplotlib)

标签:otl   print   ring   2.0   json   points   turn   .sh   figure   

原文地址:https://www.cnblogs.com/NiceTime/p/10125207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!