X label cuts off in logscale

조회 수: 2 (최근 30일)
Niklas Kurz
Niklas Kurz 2021년 1월 28일
댓글: Star Strider 2021년 6월 8일
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
Niklas Kurz
Niklas Kurz 2021년 1월 28일
I I want to custom xticks it gives me error and closest match:
/Applications/MATLAB_R2020a.app/toolbox/matlab/graph3d/xticklabels.m

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 1월 28일
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.
  댓글 수: 10
Niklas Kurz
Niklas Kurz 2021년 6월 8일
편집: Niklas Kurz 2021년 6월 8일
Thank you for laying emphasis on that difference. It still is a secret to my why that one line (NaN) causes Matlab to reduce patch to just the plotted line. It seems like the refecrence point is mimiced by the data points this way. What is kind of what we wanted.
Star Strider
Star Strider 2021년 6월 8일
As always, my pleasure!
I have long since surrendered to MATLAB being MATLAB and to just hang on and enjoy the experience!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by