# Label 0 in a semilog plot

17 views (last 30 days)
Gianluca Regina on 16 Feb 2022
Commented: Gianluca Regina on 17 Feb 2022
Dear MatLab users,
I have some data I want to plot, and the x-axis values go from 0 to 1. However, I need to plot them in a semilog plot, and for obvious mathematical reasons I cannot plot the 0, despite being a value of my data. So my question is: can I somehow add a label on the plot or on the x axis? I attached a picture which shows two possible solutions (the left one would be ideal). Below is my code for the first part of the plot, but I am utterly clueless on how to do something like that in the picture. I can use XTickLabel and write 0 but I would like to leave that as a last resort.
x = [ 0.01 , 0.05 , 0.1 ] ; % My x axis. 0.01 in reality is 0.
a = [ rand(1) , rand(1) , rand(1) ] ; % My data
b = [ rand(1) , rand(1) , rand(1) ] ; % My data
figure
errorbar( x , a , b ,'o' , 'Color' , 'k' , 'MarkerSize' ,10 , 'Capsize' , 10 , 'linewidth' , 2 , 'MarkerEdgeColor','k','MarkerFaceColor','k' );
set(gca,'xscale','log')
axis([0.01 1 -2 2])
set(gca ,'Fontsize',20,'FontWeight','bold', 'Box','on')
set(gcf , 'color','w' , 'WindowState' , 'Maximize')
grid on

Dave B on 16 Feb 2022
You can fake the tick labels, but setting the TickLabels property, but another way to do this is to use 2 axes. I like doing this kind of thing (broken axes) with tiledlayout. Note that I don't have lines coming out to 0, but that's because those lines are a little strange given the infinite space between 0 and 0.05:
rng(pi) %just for reproducibility of the random numbers
x = [ 0, 0.05 , 0.1 ];
a = rand(1,3);
b = rand(1,3);
ind0 = x==0;
t=tiledlayout(1,6);
nexttile(t)
errorbar( x(ind0) , a(ind0) , b(ind0) ,'o' , 'Color' , 'k' , 'MarkerSize' ,10 , 'Capsize' , 10 , 'linewidth' , 2 , 'MarkerEdgeColor','k','MarkerFaceColor','k' );
ax1=gca;
set(ax1,'Fontsize',20,'FontWeight','bold', 'Box','on')
nexttile([1 5])
errorbar( x(~ind0) , a(~ind0) , b(~ind0) ,'-o' , 'Color' , 'k' , 'MarkerSize' ,10 , 'Capsize' , 10 , 'linewidth' , 2 , 'MarkerEdgeColor','k','MarkerFaceColor','k' );
ax2=gca;
set(ax2,'xscale','log')
axis([0.01 1 -2 2])
set(gca,'Fontsize',20,'FontWeight','bold', 'Box','on','YTickLabel',[])
grid([ax1 ax2],'on') Gianluca Regina on 17 Feb 2022
I managed to use those commands but the plot became a bit messy and the width reduction was not worth it. Still, I can simply choose the width I desire by manually adjusting the windows figure screen. Thank you either way, and for the exportgraphics command information, though I typically use print.

### Categories

Find more on Errorbars in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!