Why is line visible while its parent axes is unvisible?

2 views (last 30 days)
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?

Answers (1)

Steven Lord
Steven Lord on 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
Steven Lord
Steven Lord on 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].

Sign in to comment.


Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by