matplotlib.axes.axes.hist()

您所在的位置:网站首页 hist函数绘制直方图 matplotlib.axes.axes.hist()

matplotlib.axes.axes.hist()

2024-05-31 19:43| 来源: 网络整理| 查看: 265

matplotlib.axes.axes.hist()

matplotlib.axes.axes.hist()函数,matplotlib库的Axes模块中的Axes.hist()函数用于绘制直方图。

语法:

Axes.hist(self, x, bins=None, range=None, density=None, weights=None, cumulative=False, bottom=None, histtype=’bar’, align=’mid’, orientation=’vertical’, rwidth=None, log=False, color=None, label=None, stacked=False, normed=None, *, data=None, **kwargs)

参数:该方法接受如下参数说明:

x:表示数据顺序。 bins:可选参数,包含整数、序列或字符串。 range:可选参数,表示容器的上下范围。 density :可选参数,包含布尔值。 weights:该参数是一个可选参数,它是一个权重数组,形状与x相同。 bottom:每个容器的底部基线位置。 histtype:可选参数,用于绘制直方图的类型。{‘ bar ‘, ‘ barstacked ‘, ‘ step ‘, ‘ stepfill ‘} align:该参数是一个可选参数,它控制如何绘制直方图。{“左”、“中”、“右”} rwidth:该参数是一个可选参数,它是条的相对宽度,作为bin宽度的一部分 log:可选参数,用于将直方图轴设置为日志级别 color:该参数是一个可选参数,它是一个颜色规格或颜色规格序列,每个数据集一个。 label:该参数是一个可选参数,它是一个字符串,或匹配多个数据集的字符串序列。 normed:该参数是一个可选参数,它包含布尔值.它使用密度关键字参数代替。

返回如下内容:

n:这将返回直方图容器的值。 bins:返回回收箱的边缘。 patch:返回用于创建直方图的单个补丁的列表。

下面的例子演示了matplotlib.axes中的matplotlib.axes.axes.hexbin()函数:

示例1 # Implementation of matplotlib function import matplotlib import numpy as np import matplotlib.pyplot as plt    np.random.seed(10**7) mu = 121   sigma = 21 x = mu + sigma * np.random.randn(1000)    num_bins = 100 fig, ax = plt.subplots()    n, bins, patches = ax.hist(x, num_bins,                            density = 1,                             color ='green',                             alpha = 0.7)    y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *      np.exp(-0.5 * (1 / sigma * (bins - mu))**2)) ax.plot(bins, y, '--', color ='black') ax.set_xlabel('X-Axis') ax.set_ylabel('Y-Axis')    ax.set_title('matplotlib.axes.Axes.hist() Example') plt.show()

输出:

matplotlib.axes.axes.hist()

示例2 # Implementation of matplotlib function import matplotlib import numpy as np import matplotlib.pyplot as plt    np.random.seed(10**7) n_bins = 20 x = np.random.randn(10000, 3)    fig, [(ax0, ax1), (ax2, ax3)] = plt.subplots(nrows = 2,                                              ncols = 2)       colors = ['green', 'blue', 'lime']    ax0.hist(x, n_bins, density = True,           histtype ='bar',          color = colors,           label = colors)    ax0.legend(prop ={'size': 10})    ax1.hist(x, n_bins, density = True,          histtype ='barstacked',          stacked = True,           color = colors)    ax2.hist(x, n_bins, histtype ='step',          stacked = True,          fill = False,           color = colors)    x_multi = [np.random.randn(n) for n in [100000,                                         80000,                                         1000]]    ax3.hist(x_multi, n_bins,           histtype ='stepfilled',          color = colors)    plt.show()

输出:

matplotlib.axes.axes.hist()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3