X label cuts off in logscale

3 views (last 30 days)
Niklas Kurz
Niklas Kurz on 28 Jan 2021
Commented: Star Strider on 8 Jun 2021
I assume the x numbers are not shown beacause the plot is squeezed too tight. How to fix it?
f = 1:0.01:20000;
db = zeros(length(f),1);
X = [f' db]; %StarStrider colormap
cm = colormap(jet);
X(end,2) = NaN;
c = (X(:,1));
p1 = plot(f,db,'b');
p2 = patch(X(:,1), X(:,2), c, 'EdgeColor','interp','LineWidth',4);
set(gca, 'XScale', 'log')
set(gca, 'FontSize',24)
legend('Frequenzgang einer idealen Box')
xlabel('Frequenz in Hz','Interpreter','latex')
ylabel(' Lautstaerke in dB','Interpreter','latex')
axis([1 20000 -20 20])
grid on
  1 Comment
Niklas Kurz
Niklas Kurz on 28 Jan 2021
I I want to custom xticks it gives me error and closest match:

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 28 Jan 2021
I do not understand what you want for the x-tick labels.
First, run your code with this to see what it does, and then adapt this to do what you want:
set(gca, 'XTick',logspace(0, log10(20000), 5), 'XTickLabel',1:5)
In general, it is necessary to define both the tick locations themselves, and the tick labels.
The labels can also be text (character arrays) or strings as cell arrays. That is sllightly more complicated, so I will not discuss it now, however I can help you with it if that is what you want to do.
Star Strider
Star Strider on 8 Jun 2021
As always, my pleasure!
I have long since surrendered to MATLAB being MATLAB and to just hang on and enjoy the experience!

Sign in to comment.

More Answers (0)


Find more on Colormaps 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!