errorbar_features
误差条形图的不同方法可以将错误指定为常数值(如errorbar_demo.py中所示)。但是,此示例通过指定错误值数组来演示它们的不同之处。 如果原始x和y数据的长度为N,则有两个选项: 数组形状为(N,): 每个点的误差都不同,但误差值是对称的(即,上下两个值相等)。 数组形状为(2, N): 每个点的误差不同,并且下限和上限(按该顺序)不同(非对称情况)。 此外,此示例演示如何使用带有误差线的对数刻度。 123456789101112131415161718192021222324import numpy as npimport matplotlib.pyplot as plt# example datax = np.arange(0.1, 4, 0.5)y = np.exp(-x)# example error bar values that vary with x-positionerror = 0.1 + 0.2 * xfig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)ax0.errorbar(x, y, ye...
hist
直方图演示如何使用matplotlib绘制直方图。 1234567import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import colorsfrom matplotlib.ticker import PercentFormatter# Fixing random state for reproducibilitynp.random.seed(19680801) 生成数据并绘制简单的直方图要生成一维直方图,我们只需要一个数字矢量。对于二维直方图,我们需要第二个矢量。我们将在下面生成两者,并显示每个向量的直方图。 123456789101112N_points = 100000n_bins = 20# Generate a normal distribution, center at x=0 and y=5x = np.random.randn(N_points)y = .4 * x + np.random.randn(100000) + 5fig, axs = plt.subplots(1, 2, ...
histogram_cumulative
使用直方图绘制累积分布这展示了如何绘制一个累积的、归一化的直方图作为一个步骤函数,以便可视化一个样本的经验累积分布函数(CDF)。文中还给出了理论上的CDF值。 演示了 hist 函数的其他几个选项。也就是说,我们使用 normed 参数来标准化直方图以及 累积 参数的几个不同选项。normed参数采用布尔值。 如果为 True ,则会对箱高进行缩放,使得柱状图的总面积为1。累积的kwarg稍微有些细微差别。与normed一样,您可以将其传递为True或False,但您也可以将其传递-1以反转分布。 由于我们显示了归一化和累积直方图,因此这些曲线实际上是样本的累积分布函数(CDF)。 在工程学中,经验CDF有时被称为“非超越”曲线。 换句话说,您可以查看给定-x值的y值,以使样本的概率和观察值不超过该x值。 例如,x轴上的值225对应于y轴上的约0.85,因此样本中的观察值不超过225的可能性为85%。相反,设置累积为-1,如同已完成 在此示例的最后一个系列中,创建“超出”曲线。 选择不同的箱数和大小会显着影响直方图的形状。Astropy文档有关于如何选择这些参数的重要部分:ht...
histogram_histtypes
演示直方图函数的不同histtype设置 具有颜色填充的步进曲线的直方图。 具有自定义和不相等的箱宽度的直方图。 选择不同的存储量和大小会显著影响直方图的形状。Astropy文档有很多关于如何选择这些参数的部分: http://docs.astropy.org/en/stable/visualization/histogram.html 123456789101112131415161718192021import numpy as npimport matplotlib.pyplot as pltnp.random.seed(19680801)mu = 200sigma = 25x = np.random.normal(mu, sigma, size=100)fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4))ax0.hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75)ax0.se...
histogram_multihist
使用多个数据集演示直方图(hist)函数绘制具有多个样本集的直方图并演示: 使用带有多个样本集的图例 堆积图 没有填充的步进曲线 不同样本量的数据集 选择不同的存储量和大小会显著影响直方图的形状。Astropy文档有很多关于如何选择这些参数的部分: http://docs.astropy.org/en/stable/visualization/histogram.html 1234567891011121314151617181920212223242526272829import numpy as npimport matplotlib.pyplot as pltnp.random.seed(19680801)n_bins = 10x = np.random.randn(1000, 3)fig, axes = plt.subplots(nrows=2, ncols=2)ax0, ax1, ax2, ax3 = axes.flatten()colors = ['red', 'tan', 'lime']ax0.his...
histogram_features
直方图(hist)函数的几个特性演示除基本直方图外,此演示还显示了一些可选功能: 设置数据箱的数量。 标准化标志,用于标准化箱高度,使直方图的积分为1.得到的直方图是概率密度函数的近似值。 设置条形的面部颜色。 设置不透明度(alpha值)。 选择不同的存储量和大小会显著影响直方图的形状。Astropy文档有很多关于如何选择这些参数的部分。 1234567891011121314151617181920212223242526272829import matplotlibimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(19680801)# example datamu = 100 # mean of distributionsigma = 15 # standard deviation of distributionx = mu + sigma * np.random.randn(437)num_bins = 50fig, ax = plt.subplots()# the histogram ...
multiple_histograms_side_by_side
并排生成多个直方图此示例沿范畴x轴绘制不同样本的水平直方图。此外,直方图被绘制成与它们的x位置对称,从而使它们与小提琴图非常相似。 为了使这个高度专门化的绘制,我们不能使用标准的 hist 方法。相反,我们使用 barh 直接绘制水平线。通过 np.histogram 函数计算棒材的垂直位置和长度。使用相同的范围(最小和最大值)和存储箱数量计算所有采样的直方图,以便每个采样的存储箱位于相同的垂直位置。 选择不同的存储量和大小会显著影响直方图的形状。Astropy文档有很多关于如何选择这些参数的部分: http://docs.astropy.org/en/stable/visualization/histogram.html 12345678910111213141516171819202122232425262728293031323334353637383940import numpy as npimport matplotlib.pyplot as pltnp.random.seed(19680801)number_of_bins = 20# An example of t...
bmh
黑客贝叶斯方法样式表这个例子演示了贝叶斯黑客方法 [1] 在线书籍中使用的风格。 [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/ 1234567891011121314151617181920from numpy.random import betaimport matplotlib.pyplot as pltplt.style.use('bmh')def plot_beta_hist(ax, a, b): ax.hist(beta(a, b, size=10000), histtype="stepfilled", bins=25, alpha=0.8, density=True)fig, ax = plt.subplots()plot_beta_hist(ax, 10, 10)plot_beta_hist(ax, 4, 12)plot_beta_hist(ax...
violinplot
小提琴图基础小提琴图类似于直方图和箱形图,因为它们显示了样本概率分布的抽象表示。小提琴图使用核密度估计(KDE)来计算样本的经验分布,而不是显示属于分类或顺序统计的数据点的计数。该计算由几个参数控制。此示例演示如何修改评估KDE的点数 (points) 以及如何修改KDE (bw_method) 的带宽。 有关小提琴图和KDE的更多信息,请参阅scikit-learn文档有一个很棒的部分:http://scikit-learn.org/stable/modules/density.html 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)# fake datafs = 10 # fontsizepos = [1, 2, 4, 5, ...
fivethirtyeight
FiveThirtyEight样式表这显示了“fivethirtyeight”样式的一个示例,它试图从FiveThirtyEight.com复制样式。 12345678910111213141516171819202122import matplotlib.pyplot as pltimport numpy as npplt.style.use('fivethirtyeight')x = np.linspace(0, 10)# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()ax.plot(x, np.sin(x) + x + np.random.randn(50))ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))ax.plot(x, np.sin(x) - 0.5 * x +...














