Clear Filters
Clear Filters

How can I keep figures invisible when toggling between axes?

4 views (last 30 days)
If I create figures using the following code
for fig=1:2
figure('papertype','A4','paperorientation','portrait','Visible','Off')
for sp=1:6
ax{fig,sp}=subplot(3,2,sp,'parent',fig);
end
end
I can then toggle between the subplots using axes, e.g., to get to subplot 4 on figure 2 I use
axes(ax{2,4})
But this makes the figure visible. Does anyone know if there's a way to keep it invisible please?
Thanks in advance for your help! Jen

Answers (2)

Rik
Rik on 15 Nov 2017
You can either use the obvious solution/workaround of calling set(gcf,'Visible','off') immediately after that line, or just avoid that line in the first place. Just about every function I can think of will accept a target axis instead of using the current axis as default.

Walter Roberson
Walter Roberson on 15 Nov 2017
Calling axes() should not cause the figure to become visible unless the axes() call is creating a new figure.
Instead of calling axes to make an axes the current axes, you can
for fig=1:2
figs(fig) = figure('papertype','A4','paperorientation','portrait','Visible','Off');
for sp=1:6
ax{fig,sp} = subplot(3, 2, sp, 'parent', figs(fig));
end
end
and later
set(figs(2), 'CurrentAxes', ax{2, 4})
But as Rik suggests, you can mostly rewrite to pass an axes in to graphics commands, either as the first parameter or using 'Parent' . There are some calls that you cannot do this for, especially when it comes to things like bode plots, or trying to pre-create both axes for use with plotyy()
  1 Comment
Jennifer Davies
Jennifer Davies on 16 Nov 2017
Thanks Walter. I have just changed
axes(ax{2, 4})
to
set(gcf, 'CurrentAxes', ax{2, 4})
and this seems to work great. Thanks!

Sign in to comment.

Categories

Find more on Specifying Target for Graphics Output 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!