Filter löschen
Filter löschen

Why is line visible while its parent axes is unvisible?

1 Ansicht (letzte 30 Tage)
Albert Bing
Albert Bing am 23 Nov. 2020
Kommentiert: Steven Lord am 23 Nov. 2020
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?

Antworten (1)

Steven Lord
Steven Lord am 23 Nov. 2020
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 Kommentare
Rik
Rik am 23 Nov. 2020
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 am 23 Nov. 2020
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].

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by