How to superimpose two figure, one to bottom right corner of larger.

3 次查看(过去 30 天)
Hello,
Figure 1 works as a visual representaion of a legend for the calculations used to produce Figure 2. I am trying to put Figure 1 in the bottom right corner of Figure 2. Is there a way to reduce the size of Figure 1 and to locate it in the lower right region of Figure 2?

采纳的回答

G A
G A 2021-7-3
编辑:G A 2021-7-3
fig1 = figure(1); % create figure1
pos1 = fig1.Position; % position of figure1: pos1 = [x1, y1, width1, hight1]
pos2 = pos1;
pos2(3) = pos1(3)/4; % width2
pos2(1) = pos1(1) + pos1(3) - pos2(3); % x2
pos2(4) = pos1(4)/4; % hight2
fig2 = figure(2); % create figure2
fig2.Position = pos2; % position of figure2 - in the right bottom corner
Or may be you need an inset?
https://uk.mathworks.com/matlabcentral/answers/60376-how-to-make-an-inset-of-matlab-figure-inside-the-figure
x=-2*pi:0.1:2*pi;
y=sin(x);
fig3 = figure(3);
clf
hold on
plot(x,y,'-r');
axes('Position',[.7 .12 .2 .2])
box on
plot(x,y,'-b');
hold off
  2 个评论
Jeffrey Gifford
Jeffrey Gifford 2021-7-6
Hi, the code seems to run but nothing is being displayed. I used the first set of code you provided and removed the semicolin on the last line but that only displays the properties.
Any suggestions?
G A
G A 2021-7-6
If you need plots, then you can plot in figure watever you wish.
x = -2*pi:0.1:2*pi;
y1 = sin(x);
y2 = cos(x);
fig1 = figure(1); % create figure1
clf
p1 = plot(x,y1,'b'); % plot sine in figure(1)
grid on
% get the position of the figure(1) and use it to define the position of
% the figure(2)
pos1 = fig1.Position; % position of figure1: pos1 = [X1, Y1, width1, hight1]
pos2 = pos1;
pos2(3) = pos1(3)/4; % width2 = width1/4
pos2(1) = pos1(1) + pos1(3) - pos2(3); % X2 coordinate of the position2 is moved to the right
pos2(4) = pos1(4)/4; % hight2 = hight1/4
fig2 = figure(2); % create figure2
clf
fig2.Position = pos2; % position of figure2 - in the right bottom corner
p2 = plot(x,y2,'r'); % plod cosine in figure(2)
grid on

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by