How to plot log-scale with number ?

50 views (last 30 days)
How can I plot log scale with the numbers like below image ?

Accepted Answer

Tommy
Tommy on 8 Jun 2020
Maybe something like this?
% data:
X = 2*logspace(1, 3, 100);
Y = rand(100,1);
% labels to keep:
labels = [20 30 50 70 100 200 300 500 1000 2000];
% prepare axes, plot:
ax = axes('XScale', 'log', 'NextPlot', 'add');
plot(ax, X, Y, '.')
ax.XLim = [20 2000];
ax.XAxis.TickDirection = 'out';
% steal the tick locations from the minor ticks, then turn the minor ticks off:
drawnow
ax.XTick = ax.XAxis.MinorTickValues;
ax.XMinorTick = 'off';
% remove labels we don't want to keep:
ax.XTickLabel(~ismember(ax.XTick, labels)) = {''};
  1 Comment
Jeevan Kumar Bodaballa
Jeevan Kumar Bodaballa on 8 Jun 2020
This is working but I'd wonder if we have any optmised code !

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 8 Jun 2020
One way is to use the semilogx function.
  3 Comments
Jeevan Kumar Bodaballa
Jeevan Kumar Bodaballa on 8 Jun 2020
Appreciated for your help and explanation. :)
Thank you

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!