Incorrect logarithmic axes after setting 'defaultAxesNextPlot' to 'add'.

조회 수: 3 (최근 30일)
Hello there,
I want to set default groot properties to simplify plot procedure. However, when I run set(groot,'defaultAxesNextPlot','add') to set 'hold on' as default, the loglog function doesn't work as it was and showed a linear axes instead.
The minimal example can be given:
x = logspace(-3,3,100);
y = (x+1)./(x+.1);
figure % before `set()`, correct
loglog(x,y)
set(groot,'defaultAxesNextPlot','add')
figure % after `set()`, incorrect
loglog(x,y)
set(groot,'defaultAxesNextPlot','remove')
figure % remove settings, correct
loglog(x,y)
You may also notice that after set(groot,'defaultAxesNextPlot','add'), the box is turned off too.
How can I correctly set plot properties to 'hold on' by default? (My MATLAB: R2021b)
Thanks for your advice/help.

채택된 답변

Nick Van Oosterwyck
Nick Van Oosterwyck 2022년 6월 17일
When you enable hold on with set(groot,'defaultAxesNextPlot','add'), the figure and axes properties become locked. Thus, because the default scale is linear, your figure will remain linear even when you use the loglog (or semilogx/semilogy) command.
In this post, the Mathworks Support Team recommends to use hold on only after the loglog, semilogx or semilogy command. However, this is not possible when you preset hold on with set(groot,'defaultAxesNextPlot','add').
Therefore, you should manually change the axes scale:
x = logspace(-3,3,100);
y = (x+1)./(x+.1);
set(groot,'defaultAxesNextPlot','add')
figure
loglog(x,y)
set(gca, 'XScale', 'log','YScale', 'log') % set log-scale manually
box on % add box manually
If you don't want to add the box manually for every figure, you can also change the default setting BEFORE creating the figures with:
set(groot,'defaultAxesBox','on');
Regards
Nick
  댓글 수: 1
Chunyu Xiao
Chunyu Xiao 2022년 6월 22일
Thanks. I just thought about the defaut 'hold on' behavior of plt.plot in Python. But, it seems not availavle in MATLAB for now to set this option by default. Maybe it will be supportted by a future version.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by