Set at least two ticks on log scales in figures
4 views (last 30 days)
Show older comments
Often when I plot a figure in log-log scale, I'll get an example like this:

You can see that there is only a single tick label on each axis, which makes it very hard to determine what the actual scale is at a glance. I can of course go in and manually fix it, but if I'm plotting potentially hundreds of similar figures for different sets of data, I'd prefer to have an automatic solution.
Is there any way to get Matlab to automatically use at least 2 tick labels on a plot? Sometimes I can just change the physical size of the window to fix things, other times I can't!
Attached is a minimal working example for the above (formatting might be slightly different as I've changed some other defaults):
figure();
hold on
x = logspace(-2.2,2.2,100);
y = x.^1.2;
plot(x,y);
axes1 = gca;
axes1.XScale = 'log';
axes1.YScale = 'log';
xlabel('$x$', 'Interpreter','latex');
ylabel('$y$', 'Interpreter','latex');
0 Comments
Answers (1)
Rik
on 24 Jan 2023
I don't know if this is an acceptable solution for you, but you could query the current tick labels and take action in your code:
CurrentTickLabels = axes1.XTickLabels
if numel(CurrentTickLabels)==1
% Do something here to manually set the tick labels
end
See Also
Categories
Find more on Interactive Control and Callbacks 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!