How to make a Subplots using set(gca,'position') command?

I would like to make one figure, with two subplots.
The dimensions for each subplot
set(gca,'Position', [0.1000 0.5971 0.2335 0.3279]) % subplot 1
hold on;
set(gca,'Position', [0.4700 0.5971 0.2335 0.3279]) % subplot 2
However, when I use this command, only the last figure axis remains, the first one disappears.
The hold on does not seem to work in this case.
Any help is greatly appriciated.
Thnak you in advance!

4 comentarios

Stephen23
Stephen23 el 1 de Mzo. de 2023
Editada: Stephen23 el 1 de Mzo. de 2023
"However, when I use this command, only the last figure axis remains, the first one disappears."
Your code only refers to one axes, which otherwise does not change and certainly does not "disappear". Nothing in your code creates or deletes axes: it simply takes one existing(?) axes and keep changing its position, that is all.
"The hold on does not seem to work in this case."
HOLD is basically unrelated to your moving one axes around the figure.
MP
MP el 1 de Mzo. de 2023
I see. Thnak you @Stephen23.
But, could you please suggest how to make two subplots with this dimension?
@MP: moved Jonas' comment to an answer. Try accepting the answer now.
Jonas
Jonas el 2 de Mzo. de 2023
thanks @Stephen23

Iniciar sesión para comentar.

 Respuesta aceptada

Jonas
Jonas el 1 de Mzo. de 2023
Movida: Stephen23 el 2 de Mzo. de 2023
you could create the axes by yourself and set the positioning as you did
figure('Color',[0.9 0.9 0.9]); % create figure and use a grey background to make the figure borders better visible here
ax1=axes('Position', [0.1000 0.5971 0.2335 0.3279]) % subplot 1
ax2=axes('Position', [0.4700 0.5971 0.2335 0.3279]) % subplot 2
but most of the time, it is sufficient and more convenient to use commands like subplot:
figure('Color',[0.9 0.9 0.9]);
subplot(1,2,1) % a 1x2 grid and we now create/make active the first (left) axis
subplot(1,2,2)
as you can see, the axes creates with subplot fill the entire figure vertically, which is most of the time the behavior one wants to have
please also note that in the first example, when creating with axes(), you have to store the axes' handles by yourself (e.g. ax1 and ax2) and in the second example, using subplot, you could (although it is not good practice) get access anytime to the axes using e.g. subplot(1,2,1) again

1 comentario

MP
MP el 2 de Mzo. de 2023
Movida: Stephen23 el 2 de Mzo. de 2023
@Jonas Thank you so much for your time and efforts. That worked!
Where isthe option to accept your answer? I am not able to find.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

MP
el 1 de Mzo. de 2023

Comentada:

el 2 de Mzo. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by