How do I set my axis values down to zero when changing my y-axis to log scale?

71 views (last 30 days)
I'm trying to get my y-axis to show log scale from 0-3, but whenever I change to log scale (from linear) it stops at about .5 or something like that. I've tried ylim and setting yticks and yticklabels and nothing I try seems to work. Help? The figure looks just how I want it to, except I want a label at zero so the rest of that error bar on the 2nd age bracket is shown.
figure(1)
clf
X=[1 2 3 4];
Y=[1 .7657621 .9677052 1.75706];
Yt=(0:.5:3);
L=(Y-[1 .5008611 .6634741 1.211559]);
U=([1 1.170767 1.411439 2.548182]-Y);
errorbar(X(2:4),Y(2:4),L(2:4),U(2:4),'sk',...
'linewidth',.5, ...
'markerfacecolor','k', ...
'markeredgecolor','k', ...
'markersize',8);
hold on; errorbar(X(1),Y(1),L(1),U(1),'*k',...
'markersize',8);
hold on; x=[.5 4.5]; y=[1 1]; plot(x,y,'--k')
ylim([0 3])
xlim([.5 4.5])
ylabel({'Odds-ratio';' '});
xlabel('Age bracket');
labelsx = {'\begin{tabular}{c} 18-24 \\(reference)\end{tabular}','25-31','32-38','39-45'};
set(gca,'XTick',X,'XTickLabel',labelsx,'TickLabelInterpreter', 'latex','Color',[1 1 1]);
set(gca,'yscale','log')
Thanks in advance for any help! Let me know if you need any more information.

Accepted Answer

Star Strider
Star Strider on 6 Jul 2016
The log of zero is -Inf. You most likely don’t want to go there. To get an idea of what your plot would look like with that lower limit, set ylim to [eps, 3]. I would use [0.45, 3] if you want a bit of space at the lower edge.

More Answers (1)

Jan Orwat
Jan Orwat on 6 Jul 2016
Edited: Jan Orwat on 6 Jul 2016
There is no zero on log scale.
Add one line on the end of your code:
...
set(gca,'yscale','log')
ylim([0.4, 3])

Community Treasure Hunt

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

Start Hunting!