bio*_*ime 10 matplotlib histogram
我matplotlib
用这个pyplot.hist()
函数创建了一个直方图.我想sqrt(binheight)
在条形图中添加bin height()的Poison错误平方根.我怎样才能做到这一点?
.hist()
包含的返回元组return[2]
- > 1个Patch对象的列表.我只能发现可以通过创建的条形图添加错误pyplot.bar()
.
ims*_*msc 12
确实你需要使用吧.您可以使用输出hist
并将其绘制为条形:
import numpy as np
import pylab as plt
data = np.array(np.random.rand(1000))
y,binEdges = np.histogram(data,bins=10)
bincenters = 0.5*(binEdges[1:]+binEdges[:-1])
menStd = np.sqrt(y)
width = 0.05
plt.bar(bincenters, y, width=width, color='r', yerr=menStd)
plt.show()
Run Code Online (Sandbox Code Playgroud)
您还可以使用pyplot.errorbar()
和drawstyle
关键字参数的组合.下面的代码使用阶梯线图创建直方图.每个箱子的中心都有一个标记,每个箱子都有必要的泊松误差条.
import numpy
import pyplot
x = numpy.random.rand(1000)
y, bin_edges = numpy.histogram(x, bins=10)
bin_centers = 0.5*(bin_edges[1:] + bin_edges[:-1])
pyplot.errorbar(
bin_centers,
y,
yerr = y**0.5,
marker = '.',
drawstyle = 'steps-mid-'
)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
当在同一图上绘制多个直方图的结果时,线图更容易区分.此外,当用a绘图时,它们看起来更好yscale='log'
.
归档时间: |
|
查看次数: |
20851 次 |
最近记录: |