How to stick one figure to the center of another figure

2 ビュー (過去 30 日間)
xiaojuezi
xiaojuezi 2020 年 8 月 18 日
回答済み: xiaojuezi 2020 年 8 月 23 日
I have a main figure f with size 1200 x 800 working as my UI. I created another figure f2 of size 512x512 which presents an image:
figure(2)
set(gcf,'units','pixels','position',[500,500,512,512]);
h1 = axes;
set(h1,'position',[0 0 1 1])
set(gca,'XAxisLocation','top','YAxisLocation','left','ydir','reverse');
set (gca, 'visible' , 'off' )
set (gca, 'xtick' , [])
set (gcf, 'color', defaultColor)
axis equal
% Plot some curves
plot(x,y)
% Rasterize
set(gcf, 'InvertHardcopy', 'off')
if ismac || isunix
img = print(gcf,'-r72','-RGBImage');
elseif ispc
img = print(gcf,'-r96','-RGBImage');
end
% Show image
imshow(img)
I tried something like this:
ax1 = gca;
copyobj(ax1,f);
This can present the image in f1, but it looks like the image is scaled, that the size is bigger than 512x512. Is there a way to stick f2 to the center of f1 as well as keeping the original size?
Thank you very much!

採用された回答

Prabhanjan Mentla
Prabhanjan Mentla 2020 年 8 月 21 日
Hi,
This question is already answered, refer the below link:
Hope this helps.

その他の回答 (1 件)

xiaojuezi
xiaojuezi 2020 年 8 月 23 日
I figured out a quick solution. Simply change the last part as:
figure(1)
imshow(img)
No need to copy the object.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by