[英]Plot standard errors(std/sqrt(N)) usiiing yerr() on a bar plot graphs
I'm pretty new to Python.我对 Python 很陌生。 I'm trying to plot a box plot for a sample data
我正在尝试为示例数据绘制箱线图
I'm trying to plot box plots of mean value of the shared data.我正在尝试绘制共享数据平均值的箱线图。 I got that part of the code.
我得到了那部分代码。 I'm also trying to plot standard error values on this box plot using
yerr()
.我还尝试使用
yerr()
在此箱线图上绘制标准误差值。
My code :我的代码:
data3=pd.read_csv('demo1.csv')
names=['brow', 'harr', 'hage', 'buch', 'mcre']
d=[data3['brow'].mean(),data3['harr'].mean(),data3['hage'].mean(),data3['buch'].mean(),data3['mcre'].mean()]
N=len(data3['co'])
l=math.sqrt(N)
k=[(data3['brow'].std())/l,(data3['harr'].std())/l,(data3['hage'].std())/l,(data3['buch'].std())/l,(data3['mcre'].std())/l,(data3['phil'].std())/l,(data3['moor'].std())/l]
fig, ax = plt.subplots()
plt.bar(names,d)
plt.bar(len(names),d,yerr=k,align='center',alpha=0.5,ecolor='black',capsize=10)
Im getting an image such as this我得到了这样的图像
But I want the black lines to be against each bar graph and not as a new bar in the plot with all of them together.但是我希望黑线与每个条形图相对,而不是将它们全部放在一起作为图中的新条形。 How can I change this.
我怎样才能改变这一点。 Am I using the plt the wrong way?
我是否以错误的方式使用 plt? Please help.
请帮忙。
I don't understand what you were trying to do with your second call to plt.bar()
我不明白你在第二次调用
plt.bar()
import math
names=['brow', 'harr', 'hage', 'buch', 'mcre']
data3 = pd.DataFrame({n: np.random.normal(loc=np.random.randint(5,10), scale=np.random.randint(1,10), size=(100,)) for n in names})
d=data3[names].mean()
N=100
l=math.sqrt(N)
k=data3[names].std()/l
fig, ax = plt.subplots()
plt.bar(names,d,yerr=k,align='center',alpha=0.5,ecolor='black',capsize=10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.