how to add errorbars
显示 更早的评论
i want to add errorbars to this graph (the error bar are "std_150,std_100 and std_control" in the code).
thanks
the code:
mw_150=[14.5,19,8.5];
mw_100=[10.42,17.4,17.7];
control=[7.15,41.9,44.3];
std_150=[1.16,1.33,0.9];
std_100=[0.83,1.01,1.09];
std_control=[0.71,1.72,1.77];
bar([1 2 3],[mw_150' mw_100' control'])
legend('150mJ/cm2','100mJ/cm2','control');
set(gca, 'FontSize',12,'XTick',[1 2 3 ],'XTickLabel',{'1.5<A.R<2.5','2.5<A.R<3.5','A.R>3.5' });
ylabel('Relative precentage')
2 个评论
dpb
2014-6-19
Not sure exactly how to envision error "bars" on a bar chart...can you describe what you think it should look like?
Only thoughts come to mind are either use a stacked bar but doesn't really seem like it would work well or use errorbar with the adjust x- coordinates for the bars and no line on the plotted line. I've not tried to see if can convince errorbar to draw the bars but not the trend line directly or whether it would take finding/setting appropriate line handle linestyle property.
aviran
2014-6-19
采纳的回答
更多回答(1 个)
...scales the matrix to put the errorbars in the middle of the plotted bars, and I have no idea how MATLAB determines where it puts those bars. The handle graphics don’t say, because all the 'XData' values are the same for all variables. I cannot find anything in the documentation that alludes to where they are stored or how they are calculated...
Got's to go handle-diving Star--they're not identified per se, but you can compute the location by retrieving the XData property from the barseries object patch...
For the sample above for the first handle, one can find
>> xtik=get(get(hb(1),'children'),'xdata')
xtik =
0.6545 1.6545 2.6545
0.6545 1.6545 2.6545
0.8000 1.8000 2.8000
0.8000 1.8000 2.8000
>> mean(xtik(1:2:end,:))
ans =
0.7273 1.7273 2.7273
>>
By comparison, your heuristic values were
>> ([1]-mv)*sclf+[1:3]
ans =
0.7300 1.7300 2.7300
>>
Not bad... :)
2 个评论
Star Strider
2014-6-19
Thank you! I went handle-diving, but apparently not deep enough.
dpb
2014-6-19
No problem...came up with this w/ a poster's help when labeling a bar series w/ values. I'd always used a heuristic based on a the 'Width' parameter before but it wasn't completely reliable, either. This returns the real deal of where actually draws the patch object so is dead on...
类别
在 帮助中心 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!