Why is line visible while its parent axes is unvisible?

조회 수: 1 (최근 30일)
Albert Bing
Albert Bing 2020년 11월 23일
댓글: Steven Lord 2020년 11월 23일
Say a script as following,
fig = figure;
ax = axes(fig, 'Visible', 'on');
plot(ax, 1:8, cos(pi*(1:8)),'r-x');
set(ax, 'Visible', 'off');
Why is the line still visible?

답변 (1개)

Steven Lord
Steven Lord 2020년 11월 23일
Because the line has its own Visible property and that property's value is 'on'.
fig = figure;
ax = axes(fig, 'Visible', 'on');
h = plot(ax, 1:8, cos(pi*(1:8)),'r-x');
set(ax, 'Visible', 'off');
lineVisiblePropertyValue = h.Visible
lineVisiblePropertyValue =
OnOffSwitchState enumeration on
  댓글 수: 2
Rik
Rik 2020년 11월 23일
I would have expected the line object to follow the parent axes property (just like would happen if you set(fig, 'Visible', 'off');). I understand why it doesn't work like that, but that is what I would expected.
Steven Lord
Steven Lord 2020년 11월 23일
Just because two or more Handle Graphics objects have properties with the same name doesn't mean those properties are synchronized. In the code below, changing the figure's Color property does not change the Color properties of the axes or the line inside the figure.
h = plot(1:10);
ax = ancestor(h, 'axes');
f = ancestor(h, 'figure');
f.Color = 'r';
fprintf("%s", "The line has color [" + join(string(h.Color), ",") + "] " + ...
"while the axes has color [" + join(string(ax.Color), ",") + "] " + ...
"and the figure has color [" + join(string(f.Color), ",") + "].")
The line has color [0,0.447,0.741] while the axes has color [1,1,1] and the figure has color [1,0,0].

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by