How to set axes in a figure without displaying the figure
11 次查看(过去 30 天)
显示 更早的评论
I have this code to create two axis object
ax1 = axes;
xlabel('$x/h$','interpreter','latex')
ylabel('$y/h$','interpreter','latex')
zlabel('$z/h$','interpreter','latex')
shading interp;
ax2 = axes;
xlabel('$x/h$','interpreter','latex')
ylabel('$y/h$','interpreter','latex')
zlabel('$z/h$','interpreter','latex')
shading interp;
linkaxes([ax1,ax2]);
ax2.Visible='off';
ax2.XTick = [];
ax2.YTick = [];
colormap(ax1,'cool');
colormap(ax2,'hot');
Then I want to use it in a figure without opening it, just to print it, so I tried this but it does not work:
figure(Visible="off")
axes(ax1)
isosurface(x,y,z,solution,intensity)
hold on
axes(ax2)
isosurface(x2,y2,z2,solution2,intensity2);
print(....)
At lines axes(ax1) and axes(ax2) a figure opens and I can't fix it, I need a way to plot and print this with no pop-up figure at all.
Thank you in advance
0 个评论
回答(1 个)
Jan
2022-5-12
编辑:Jan
2022-5-12
axes(ax1) activates the already created axes with the handle ax1. [EDITED] And it enables the visibility of the figure automatically. [/EDITED]
Try to insert the code for opening the axes after the figure(Visible="off") such that the axes are created inside the invisible figure. To be sure, define the parents explicitly:
FigH = figure(Visible="off");
ax1 = axes('Parent', FigH);
xlabel(ax1, '$x/h$','interpreter','latex')
...
There have been several limitations with printing invisible figures in former Matlab versions. Try, if this is working at all. A workaround would be to create the figure visibly, but outside the visible area of the screen.
3 个评论
Jan
2022-5-12
编辑:Jan
2022-5-12
FigH = figure('Visible', 'off');
AxesH = axes('Parent', FigH);
drawnow;
disp(get(FigH, 'Visible')); % 'off'
% axes(AxesH); % Omit this, because this enables the visibility!
plot(AxesH, 1:10, rand(10, 10)); % Define the parent instead
disp(get(FigH, 'Visible')); % 'off' !!!
It is fragile to rely on the current obect is selected as parent automagically. This is convenient, but as soon as a user click on another object during the creation or as in your case, the effects are unexpected and strange. The good programming style is to spent the time to define the parent in general without any exception.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!