![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174432/image.jpeg)
Error bars added to column plot instead of regular line plot, and stacked 2x2
1 次查看(过去 30 天)
显示 更早的评论
I would like to create a 2x2 plot with error bars, where each mean is represented by a column rather than by a marker (data point), something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165997/image.jpeg)
The errorbar function in Matlab seems to not have the option to make columns instead of simple markers, and also no option to stack the four entities as 2x2, instead giving me something that looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165999/image.jpeg)
0 个评论
采纳的回答
dpb
2016-6-8
编辑:dpb
2016-6-11
Would be worth a search on File Exchange to see if somebody has submitted a function, but--
It's somewhat of a pit(proverbial)a(ppendage) to do, but is achievable with bar and errorbar
A trivial sample --
>> y=randi(6,[2,2]); % trivial dataset
y =
1 2
4 5
>> hB=bar(y); % make a bar plot of y data
>> ylim([0 6]) % make y axes look better
>> hold on % get ready to add errorbar on top of
>> barX=get(cell2mat(get(hB,'children')),'xdata'); % bar x-data (patches x locations)
>> barXpos=cell2mat(cellfun(@mean,barX,'uniform',0)).'; % return x position of midpoint of bars
>> arrayfun(@errorbar,barXpos,y,zeros(size(y)),0.1*y) % add the error bar at top+10% range
>>
The above gives the following image--
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174432/image.jpeg)
Fix up the colors as desired and perhaps(?) a heavier line width, but shows the way to get the hard piece of data--where's the center of each bar drawn by bar? that's not a retrievable property; the above computes it as the average of the face positions.
Using arrayfun to invoke errorbar saves the drawing of the line between the points if used the array; that's also solvable by using linestyle but this seems pretty easy workaround to simply pass each element one-at-a-time. Do need an array of associated colors to match, of course...
Hope that helps...seems more trouble than should be, granted...
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!