# How to add (minor) ticks on loglog plot?

172 views (last 30 days)
Elin on 2 Oct 2014
Commented: Star Strider on 29 Apr 2021
I plot my data in log scale and some of the graphs don't have any ticks at all. I have tried to add ticks on the y-axis on the loglog plots, but the axis scale then changes back from log-scale to normal scale.
These are some of the different settings that I have tried:
1) set a fixed tick scale:
set(gca, 'YTick', [10.^0 10^0.4 10^0.8 10^1 10^1.3 ])
2) set a tick range:
set(gca, 'YTick', [0.001: 4 : 13])
3) Turn the minor tick function on:
set(gca,'YMinorTick','on')
So, how do I add ticks and keep the log scale? I work in Matlab 2012a, Mac OSX
/ Elin

dpb on 2 Oct 2014
Star Strider on 29 Apr 2021
The Newsreader has been gone for several years. You might be able to find it archived on Google Groups or something similar if you enjioy spelunking Usenet archives.

Star Strider on 2 Oct 2014
Edited: Star Strider on 2 Oct 2014
This works with this code. You may have to experiment with it with your plot:
x = logspace(-1,1.5);
y = exp(x);
figure(1) % Default Behaviour
loglog(x,y,'-s');
grid on
figure(2) % Selected Behaviour
loglog(x,y,'-s');
grid on
yt = get(gca, 'YTick');
ytkvct = 10.^linspace(1, 10*size(yt,2), 10*size(yt,2));
set(gca, 'YTick', ytkvct);
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
produces this plot:

Harshad Deshmane on 2 Oct 2014
I created a sample "loglog" plot and tried changing the ticks and turning on minor ticks on the y-axis. I followed the approach that you mentioned. But the axis scale did not change from log to linear for me. (I used MATLAB R2012a on Mac OSX 10.9.2.)
One thing you can try is to click on the 'Show Plot Tools and Dock Figure' button on the figure window. This will open a UI which allows you to make any changes to your figure/axes. You can click inside the axes and set the Y scale, change the tick locations and labels, and turn on/off minor ticks.
dpb on 3 Oct 2014
Ayup...which is why the use of text is the way instead of adding more major ticks if want to keep the same exponential formatting as the default.
Now again, here's one of the unsolved mysteries/frustrations with handle graphics--since they go to the trouble to initially write the exponential form, why doesn't set for the case of log scale have the internal smarts to at least write other integer-valued tick values in the same format (or better yet have a formatting property that gives the user the flexibility to specify the format desired)?
As is, as is so often the case, the actual look of graphics just isn't as professional as one would like for presentation purposes at least without the user taking a lot of time and effort to fix up such faux pas. One that just bugs me no end that's trivial to fix but has been around "since forever" is the missing decimal ".0" at the origin and upper limits in the default axes -- it's simply just tacky as is.