Keeping Error Bars while Subplotting

조회 수: 8 (최근 30일)
Yugarshi Mondal
Yugarshi Mondal 2019년 7월 27일
답변: Yugarshi Mondal 2019년 7월 27일
I've written the following code which takes plotted data and dumps it into a subplot. I want to annotate each of the subplots with an error bar and some text. However, when i go to draw the error bars, the actual figure gets erased! (Notice even the x & y labeling gets erased)
What am I doing wrong? Here's my code:
figs = [2 4 3 6];
for j=1:4
endX = 200;
newh = copyobj(allchild(get(figs(j),'CurrentAxes')),h(j));
ylim(h(j), [0 .5]); ylabel(h(j),'S');
xlim(h(j), [0 endX]); xlabel(h(j), 'Time (ms)');
dataObjs = findobj(h(j),'-property','YData');
pks = findpeaks(dataObjs.YData); trs = findpeaks(-1*dataObjs.YData)*-1; ampSS = pks(end) - trs(end);
bracket = errorbar(h(j),endX,trs(end) + ampSS/2, ampSS/2,'vertical','linewidth',1.5);
txt = text(h(j),endX,trs(end) - .02, strcat('Amp = ',num2str(ampSS)), 'horizontalalignment','center','verticalalignment','top','fontsize',8);
end
Note that commenting the line with "bracket = ..." results in the orginal plot with annotations. So its a problem with errorbar.

답변 (1개)

Yugarshi Mondal
Yugarshi Mondal 2019년 7월 27일
Adding the following code before calling errorbar solves the this. I think the error bar must be drawn using plot, and so holding as if you were plotting another line on the same subplot fixes this.
set(h(j),'NextPlot','add');

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by