How can I keep figures invisible when toggling between axes?

4 次查看(过去 30 天)
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

回答(2 个)

Rik
Rik 2017-11-15
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 2017-11-15
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 个评论
Jennifer Davies
Jennifer Davies 2017-11-16
Thanks Walter. I have just changed
axes(ax{2, 4})
to
set(gcf, 'CurrentAxes', ax{2, 4})
and this seems to work great. Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by