使用matplotlib绘制柱状图

matplotlib中的hist方法

matplotlib.pyplot.hist(x,bins = None,range = None,density = None,weights = None,cumulative = False,bottom = None,histt​​ype ='bar',align ='mid',orientation ='vertical',rwidth = None,log = False,color = None,label = None,stacked = False,normed = None,*,data = None,** kwargs )

主要参数说明:

参数参数说明
x输入值(数组或序列)
bins图形的边缘(可选)
range横坐标的上限和下限(可选)
density如果True,返回元组的第一个元素将被归一化以形成概率密度的计数,(可选)
weightsx的权重
cumulative如果True,则计算直方图,其中每个bin给出该bin中的计数加上较小值的所有bin。最后一个bin给出了数据点的总数。
bottom每个bin的底部基线的位置
histtype要绘制的直方图的类型
align控制直方图的绘制方式
rwidth条的相对宽度
log如果True,直方图轴将设置为对数刻度。
color颜色规格或颜色规格序列,每个数据集一个
label字符串或匹配多个数据集的字符串序列
stacked如果True,多个数据堆叠在一起如果 False多个数据并排排列

随机生成一个柱状图:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.normal(size=100)
plt.hist(x)

plt.show()

在这里插入图片描述


随机生成更复杂的柱状图:

import matplotlib.pyplot as plt
import numpy as np
        
plt.figure()
x = np.random.gamma(3,4,200)
plt.subplot(221)
plt.hist(x,bins = 30)
plt.subplot(222)
plt.hist(x,bins = 30,normed=True)
plt.subplot(223)
plt.hist(x,bins = 30,cumulative=True)
plt.subplot(224)
plt.hist(x,bins = 30,normed=True,cumulative=30,histtype="step")

plt.show()

在这里插入图片描述


("The only person standing in your way is you."--《Black Swan》)

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值