Why is line visible while its parent axes is unvisible?

1 visualizzazione (ultimi 30 giorni)
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?

Risposte (1)

Steven Lord
Steven Lord il 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 Commenti
Rik il 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 il 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].

Accedi per commentare.


Scopri di più su Graphics Object Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by