Set at least two ticks on log scales in figures
3 views (last 30 days)
Show older comments
Commented: Isaac Pincus on 24 Jan 2023
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):
x = logspace(-2.2,2.2,100);
y = x.^1.2;
axes1 = gca;
axes1.XScale = 'log';
axes1.YScale = 'log';
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
% Do something here to manually set the tick labels
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!