数据科学入门与实战:Matplotlib绘图hist

直方图就是可以看数据整体分布情况

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
s = Series(np.random.randn(1000))
print(s)
plt.hist(s)

在这里插入图片描述
在这里插入图片描述
调整柱子宽度

plt.hist(s,rwidth=0.5)

在这里插入图片描述
另一个例子

#另一个例子
a = np.arange(10)
print(a)
plt.hist(a,rwidth=0.8)

在这里插入图片描述

re = plt.hist(s,rwidth=0.9)
print(re)
print(type(re))
print(len(re))
print('-----------')
(array([  7.,  26.,  84., 202., 282., 205., 116.,  58.,  17.,   3.]), array([-3.10819617, -2.44536828, -1.78254038, -1.11971249, -0.45688459,
        0.2059433 ,  0.8687712 ,  1.53159909,  2.19442699,  2.85725488,
        3.52008278]), <a list of 10 Patch objects>)
<class 'tuple'>
3
print(re[0])#代表出现的次数
print(re[1])#间隔
print(re[2])#list十个矩形

在这里插入图片描述
在这里插入图片描述
20个矩形

#20个矩形~
plt.hist(s,rwidth=0.9,bins=20)

在这里插入图片描述

plt.hist(s,rwidth=0.9,bins=20,color='r',stacked = False)#还可以变成水平的。。

在这里插入图片描述

#密度图kind默认为line
s.plot(kind = 'kde')#密度图

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值