필터 지우기
필터 지우기

How to set axes in a figure without displaying the figure

조회 수: 10 (최근 30일)
David Gonzalez Ceballos
David Gonzalez Ceballos 2022년 5월 12일
댓글: David Gonzalez Ceballos 2022년 5월 16일
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

답변 (1개)

Jan
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
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.
David Gonzalez Ceballos
David Gonzalez Ceballos 2022년 5월 16일
Ok, thank you very much for your answers

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by