Why is line visible while its parent axes is unvisible?

1 visualización (últimos 30 días)
Albert Bing
Albert Bing el 23 de Nov. de 2020
Comentada: Steven Lord el 23 de Nov. de 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?

Respuestas (1)

Steven Lord
Steven Lord el 23 de Nov. de 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 comentarios
Rik
Rik el 23 de Nov. de 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 el 23 de Nov. de 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].

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by