How to keep the same size in figures
70 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
David Gonzalez Ceballos
le 31 Mai 2022
Réponse apportée : Eduardo Vicente Wolf Trentini
le 26 Nov 2022
I have the code at the bottom of the page.
The code is executed inside a function inside a for loop so for every iteration t of the loop an image is saved.
I want to use those images to make a video by displaying them one after the other but when doing that they are a bit moved, I mean, the axes are not in the exact same position in every image so when changing form one to the next sometimes there is a gap and the video looks awful. Data in every iteration is very similar an axis limits are exactly the same and data never exceed axis limits. How can I do to create images with the axes in the same position and with the same exact size?
Thank you in advance
Fig1 = figure(Visible="off");
ax1 = axes('Parent',Fig1);
xlabel('$z/h$','interpreter','latex','color','w')
ylabel('$x/h$','interpreter','latex','color','w')
zlabel('$y/h$','interpreter','latex','color','w')
set(gca,'fontsize',12,'color','k')
shading interp;
ax1.XColor = 'white';
ax1.YColor = 'white';
ax1.ZColor = 'white';
xlim ([0 xmax]);
ylim ([0 ymax]);
zlim ([0 zmax]);
axis tickaligned
axes(ax1)
set(gcf,Visible='Off')
isosurface(x,y,z,sol,treshold);
lighting phong
box on;
view(52,27)
axis equal
axis tickaligned;
h = camlight;
set(h,'style','infinite')
set(h,'position',[3 -5 15])
xlim ([0 xmax]);
ylim ([0 ymax]);
zlim ([0 zmax]);
set(gcf,'color','k')
print(fullfile(figuresdir, strcat('number', num2str(t))), '-dpng','-r400');
0 commentaires
Réponses (2)
Biral Pradhan
le 3 Juin 2022
I understand, you are generating plot images iteratively, and want to control axis layout. Kindly follow the documentation link below to resolve the issue.
0 commentaires
Eduardo Vicente Wolf Trentini
le 26 Nov 2022
I had the same problem as you and finally managed to solve it.
The problem is the camera's field of view. I don't know why matlab changes it from figure to figure even though the axes limits are the same.
In my case a value of 6.1 fits the figure, in yours it may be different.
To be a fixed value in your case, I believe it is like this:
ax1.CameraViewAngle = 6.1;
In my case I solved it like this:
mygca = gca;
mygca.CameraViewAngle = 6.1;
You must set this value every time you create a new figure.
If a difference still persists you can try to fix the position too:
mygca.Position = [0 0 1 1];
0 commentaires
Voir également
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!