semilogy, loglog do not work in order to set the y axis on a logarithmic scale

조회 수: 27 (최근 30일)
I am working on a numerical algorithm and I want to plot the error for 5 different shape parameters of my function. I want all the plots to figure on one same figure.
Here is the code that I use:
figure
hold on
for i=3:7
[coord_ctrs, errors] = ApproxAdap1D(i);
semilogy(coord_ctrs, (errors));
title("Senkung des RMS Fehlers");
grid;
end
Result:
As you can see, it does not work, the y axis does not have a logarithmic scale. loglog function displays tthe same result too.

채택된 답변

Jan
Jan 2021년 9월 12일
편집: Jan 2021년 9월 12일
After figure, hold on the YScale is determined already. Define it explicitly instead and you plot():
figure
axes('yscale', 'log');
hold on
title("Senkung des RMS Fehlers");
for i=3:7
plot(1:10, rand(1, 10));
end

추가 답변 (1개)

Dave B
Dave B 2021년 9월 12일
When you use the log plotting functions they don't change the axis scale if hold is on. There's a note all the way at the bottom of the documentation pages (oddly, in algorithms). Here's the one from the semilogx page:
The semilogx function plots x-coordinates on a log scale by setting the XScale property of the axes to 'log'. However, if the axes hold state is 'on' before you call semilogx, the property does not change, and the x-coordinates might display on a linear scale.
Fortunately you can just set the relevant scale property:
hold on
for i = 1:3
plot(1:10,2*(rand(10,1)*i))
end
set(gca,'YScale','log')

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by