How to set axes in a figure without displaying the figure

17 visualizaciones (últimos 30 días)
David Gonzalez Ceballos
David Gonzalez Ceballos el 12 de Mayo de 2022
Comentada: David Gonzalez Ceballos el 16 de Mayo de 2022
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

Respuestas (1)

Jan
Jan el 12 de Mayo de 2022
Editada: Jan el 12 de Mayo de 2022
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 comentarios
Jan
Jan el 12 de Mayo de 2022
Editada: Jan el 12 de Mayo de 2022
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 el 16 de Mayo de 2022
Ok, thank you very much for your answers

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by