필터 지우기
필터 지우기

Error bars added to column plot instead of regular line plot, and stacked 2x2

조회 수: 3 (최근 30일)
z8080
z8080 2016년 6월 8일
편집: dpb 2016년 6월 11일
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:
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:

채택된 답변

dpb
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--
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개)

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by