matplotlib.pyplot.hist()

matplotlib.pyplot.hist(xbins=Nonerange=Nonenormed=Falseweights=Nonecumulative=False,

 bottom=Nonehisttype='bar'align='mid'orientation='vertical'rwidth=Nonelog=Falsecolor=None

label=Nonestacked=Falsehold=Nonedata=None**kwargs)

Plot a histogram.

Compute and draw the histogram of x. The return value is a tuple (nbinspatches) or ([n0n1, ...], bins, [patches0patches1,...]) if the input contains multiple data.

Multiple data can be provided via x as a list of datasets of potentially different length ([x0x1, ...]), or as a 2-D ndarray in which each column is a dataset. Note that the ndarray form is transposed relative to the list form.

Masked arrays are not supported at present.

Parameters:

x : (n,) array or sequence of (n,) arrays

Input values, this takes either a single array or a sequency of arrays which are not required to be of the same length

bins : integer or array_like or ‘auto’, optional

If an integer is given, bins + 1 bin edges are returned, consistently with numpy.histogram() for numpy version >= 1.3.

Unequally spaced bins are supported if bins is a sequence.

If Numpy 1.11 is installed, may also be 'auto'.

Default is taken from the rcParam hist.bins.

----------

numpy.histogram(abins=10range=Nonenormed=Falseweights=Nonedensity=None)

bins : int or sequence of scalars, optional

If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths.


-----------

range : tuple or None, optional

The lower and upper range of the bins. Lower and upper outliers are ignored. If not provided, range is (x.min(), x.max()). Range has no effect if bins is a sequence.

If bins is a sequence or range is specified, autoscaling is based on the specified bin range instead of the range of x.

Default is None

normed : boolean, optional

If True, the first element of the return tuple will be the counts normalized to form a probability density, i.e.,n/(len(x)`dbin), i.e., the integral of the histogram will sum to 1. If stacked is also True, the sum of the histograms is normalized to 1.

Default is False

weights : (n, ) array_like or None, optional

An array of weights, of the same shape as x. Each value in x only contributes its associated weight towards the bin count (instead of 1). If normed is True, the weights are normalized, so that the integral of the density over the range remains 1.

Default is None

cumulative : boolean, optional

If True, then a histogram is computed where each bin gives the counts in that bin plus all bins for smaller values. The last bin gives the total number of datapoints. If normed is also True then the histogram is normalized such that the last bin equals 1. If cumulative evaluates to less than 0 (e.g., -1), the direction of accumulation is reversed. In this case, if normed is also True, then the histogram is normalized such that the first bin equals 1.

Default is False

bottom : array_like, scalar, or None

Location of the bottom baseline of each bin. If a scalar, the base line for each bin is shifted by the same amount. If an array, each bin is shifted independently and the length of bottom must match the number of bins. If None, defaults to 0.

Default is None

histtype : {‘bar’, ‘barstacked’, ‘step’, ‘stepfilled’}, optional

The type of histogram to draw.

  • ‘bar’ is a traditional bar-type histogram. If multiple data are given the bars are aranged side by side.
  • ‘barstacked’ is a bar-type histogram where multiple data are stacked on top of each other.
  • ‘step’ generates a lineplot that is by default unfilled.
  • ‘stepfilled’ generates a lineplot that is by default filled.

Default is ‘bar’

align : {‘left’, ‘mid’, ‘right’}, optional

Controls how the histogram is plotted.

  • ‘left’: bars are centered on the left bin edges.
  • ‘mid’: bars are centered between the bin edges.
  • ‘right’: bars are centered on the right bin edges.

Default is ‘mid’

orientation : {‘horizontal’, ‘vertical’}, optional

If ‘horizontal’, barh will be used for bar-type histograms and the bottom kwarg will be the left edges.

rwidth : scalar or None, optional

The relative width of the bars as a fraction of the bin width. If None, automatically compute the width.

Ignored if histtype is ‘step’ or ‘stepfilled’.

Default is None

log : boolean, optional

If True, the histogram axis will be set to a log scale. If log is True and x is a 1D array, empty bins will be filtered out and only the non-empty (nbinspatches) will be returned.

Default is False

color : color or array_like of colors or None, optional

Color spec or sequence of color specs, one per dataset. Default (None) uses the standard line color sequence.

Default is None

label : string or None, optional

String, or sequence of strings to match multiple datasets. Bar charts yield multiple patches per dataset, but only the first gets the label, so that the legend command will work as expected.

default is None

stacked : boolean, optional

If True, multiple data are stacked on top of each other If False multiple data are aranged side by side if histtype is ‘bar’ or on top of each other if histtype is ‘step’

Default is False

Returns:

n : array or list of arrays

The values of the histogram bins. See normed and weights for a description of the possible semantics. If input x is an array, then this is an array of length nbins. If input is a sequence arrays [data1, data2,..], then this is a list of arrays with the values of the histograms for each of the arrays in the same order.

bins : array

The edges of the bins. Length nbins + 1 (nbins left edges and right edge of last bin). Always a single array even when multiple data sets are passed in.

patches : list or list of lists

Silent list of individual patches used to create the histogram or list of such list if multiple input datasets.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Matplotlib.pyplot.hist函数用于绘制直方图,它可以接受一维数组作为输入,然后将数据分成若干个区间,统计每个区间内数据的数量,并将结果绘制成直方图。该函数有多个参数可以调整直方图的样式和布局,比如bins参数可以指定区间的数量,range参数可以指定数据的范围等。 ### 回答2: MatplotlibPython的一个绘图库,而pyplotMatplotlib的一个子模块。Matplotlib.pyplot.hist函数用于绘制直方图。 直方图是一种统计图表,用来表示数据的分布情况。直方图将数据划分为若干个等宽的区间,通过统计落入每个区间的数据个数来展示数据的分布情况。 使用Matplotlib.pyplot.hist函数绘制直方图时,需要输入一个数据集作为参数。函数将根据数据集中的值来统计落入每个区间的数据个数,并根据统计结果绘制直方图。 该函数的常见参数包括: - bins:用于指定划分区间的个数或区间的边界值。默认为10,意味着将数据划分为10个等宽的区间。 - range:用于指定数据的范围,超出该范围的数据将被忽略。 - density:用于控制是否将直方图的纵轴单位设置为概率密度。默认为False,即纵轴单位为数据个数。 - color:用于指定直方图的颜色。 - alpha:用于指定直方图的透明度。 - label:用于给直方图添加标签。 除了常见参数外,还可以通过调整其他参数来进一步调整直方图的样式,如设置边界宽度、设置直方图的类型等。 总之,使用Matplotlib.pyplot.hist函数可以方便地绘制直方图,帮助我们更直观地了解数据的分布情况。 ### 回答3: Matplotlib.pyplot.hist函数用于绘制直方图。直方图是一种用来展示数据分布情况的统计图表。该函数可以将数据划分为一系列的间隔,并统计落在每个间隔内的数据个数,然后以柱形图的形式显示出来。 使用该函数,首先需要传入要绘制直方图的数据,可以是一个数组或者一列数据。函数会自动根据数据的最小值和最大值确定需要划分的间隔数。也可以通过设置bins参数来指定间隔数,或者通过设置range参数来指定数据的范围。 在绘制直方图时,可以设置一些可选参数来调整图表的样式。例如,可以通过设置color参数来改变柱形的颜色;通过设置alpha参数来调整柱形的透明度;通过设置edgecolor参数来改变柱形之间的边界颜色。 此外,还可以通过设置normed参数为True来将每个柱形的高度转化为概率密度。通过设置cumulative参数为True,可以绘制累积直方图。 绘制直方图后,还可以添加一些额外的元素,例如标题、横轴和纵轴标签、图例等。 总的来说,Matplotlib.pyplot.hist函数是一个简单而强大的绘制直方图的工具,可以方便地展示数据的分布情况,进而提供数据分析的依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值