error bars plotting only on one side of the data points on a semi log plot

Hello everyone!
i am plotting error bars in a semi log plot (code attached)
for some strange reason matlab is plotting the error bars only from one side for some of the data points , and from two sides for others.(figure attached in the pdf file)
did someone ever encounter such a problem? i know that the error bars will not be symetrical with reference to the data point because of the log scale on the y axis, but they should not completely disappear from one of the sides! (the data series i am talking about are the small diamonds)
error bars only from one side.jpg
scatter(Galactocentricradius,asqbsqnorm,...
'DisplayName','2A^2+5B^2 normalized',...
'MarkerEdgeColor',[0 0 0],...
'Marker','diamond');
hold on;
scatter(Galactocentricradius,SFRNORMALIZED,...
'DisplayName','\Sigma{sfr}/\Sigma sfr_{total}',...
'MarkerEdgeColor',[0 0 0],...
'Marker','hexagram','SizeData',50,'MarkerFaceColor',[0.501960784313725 0.501960784313725 0.501960784313725]);
errorbar(Galactocentricradius,asqbsqnorm,errorbar2a25b2norm,'handlevisibility','off','Color',[0.15 0.15 0.15],'capsize',1);
errorbar(Galactocentricradius,SFRNORMALIZED,erroronSFRnormalized,'handlevisibility','off','Color',[0.15 0.15 0.15],'capsize',1);
set(gca,'Yscale','log');
ylim([0.0001,1]);

 Accepted Answer

Check and you'll find the lower limit for those not plotted is <0 which can't be represented on log axis.

9 Comments

Hello! Thanx for your answer. But The error on these not plotted is not negative ,actually all my error bars are positive. So the problem is somewhere else.
"...rhe error on these not plotted is not negative ,actually all my error bars are positive"
You'll have to prove it before I'll believe it's something else... :)
The errors are positive but (y-err)<=0
As you can see by looking at the plot, the lower limits are smaller and smaller--the last two positive ones are <10E-4 as they go off the bottom of the lower ylim setting. The next one is (and all the rest are) negative.
Attach the data(*) and I'll demonstrate...or find the other culprit if is lurking but my money is on the first...
(*) Or save as .fig and attach it; can read the data out of it...altho a .mat file of the data would be smaller.
ADDENDUM:
Did you not get a warning
>> hAx.YScale='log';
Warning: Negative data ignored
>>
I'll bet you did and just didn't recognize the cause...
dpb!! thank you soo much for your answer.
yes i checked the data and you are aboslutely right! THANK YOU
is there a way i can force all error bars to a default value once y-err is smaller than 0?
and btw i didnt get the message
hAx.YScale='log';Warning: Negative data ignored
That's peculiar the negative log data warning would be off...unusual.
The only way to prevent the errorbar whiskers from going negative by applying the symmetric error value inside errorbar() would be to specify both upper and negative error limits. This wouldn't be too bad, something like
errorbar(Galactocentricradius,SFRNORMALIZED, ...
SFRNORMALIZED+erroronSFRnormalized, ...
max(SFRNORMALIZED-erroronSFRnormalized,1E-6), ...
'handlevisibility','off','Color',[0.15 0.15 0.15], ...
'capsize',1);
THANK YOU soooo much for your prompt help
i tried your code now the error bars below the data points have all disappeared and the ones above are too small
i have attached the .fig file as you suggested
the code i have written is exactly what you proposed (note that it should not apply on SFRnormalized rather on the diamonds data points which are asqbsqnorm.
attached my exact code
errorbar(Galactocentricradius,asqbsqnorm,asqbsqnorm+errorbar2a25b2norm,max(asqbsqnorm-errorbar2a25b2norm,1E-6),'handlevisibility','off','Color',[0.15 0.15 0.15],'capsize',1);
OK, that was a misstep -- the pos, neg errors are still errors/deltas, not the absolute values...I tried to get too clever and avoid having to have an intermediary step...use
perr=errorbar2a25b2norm;
nerr=perr;
isneg=(asqbsqnorm-nerr)<=0;
nerr(isneg)=asqbsqnorm(isneg)-1E-6;
errorbar(Galactocentricradius,asqbsqnorm,nerr,perr, ...
'handlevisibility','off','Color',[0.15 0.15 0.15],'capsize',1);
This computes a negative error such that the error bar will be at 1E-6 for those who would otherwise be negative using base values.
While this solves the issue of having a plot on log scale, not indicating a bound includes zero by truncating it, even if at a small positive value, could be considered highly misleading and I don't encourage it at all...at least without a caveat -- like maybe make those locations a different color or somesuch to indicate what was done.
THANK YOU again and again and sorry to trouble you with this problem
nerr(isneg)=asqbsqnorm-1E-6;
there seems to be an error in this line of code the code is not working.it is pointing at an error here.
i tpropose the following idea : when y-err=<0 then it should automatically take nerr =asqbsqnorm*0.9 (like 90 % of the value so it always remains above zero)
i tried this but it also doesnt work : nerr(isneg)= asqbsqnorm.*0.9
any idea why?
You can compute it however you wish, the preceding of a small but positive lower limit shows up on your graph by going off the bottom unended which at least shows that it's large in that direction. The 90% value may or may not have such properties. But, it's your call: I'll just note the previous caveats.
The error is I didn't cut 'n paste but typed into the edit window and left off the (isneg) addressing array on the RHS. I fixed the above code snippet.
THANK YOU SOO MUCH!!you were extremely helpfull.MANY THANKS

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 6 Aug 2019

Edited:

dpb
on 8 Aug 2019

Community Treasure Hunt

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

Start Hunting!