Matlab多个Figure图合成一个Fig

Matlab多个Figure图合成一个Fig
转自:http://jacoxu.com/matlab%E5%A4%9A%E4%B8%AA%E5%B7%B2figure%E5%9B%BE%E5%90%88%E6%88%90%E4%B8%80%E4%B8%AA/
案例:之前跑过的程序 已经生成了多个matlab图,现在需要进行合并到一个图中。
解决方案,利用图像句柄把figure图像中的参数读入到内存中,然后重新subplot绘制。

clc;clear;   
open(‘./test_1.fig’)   
figure_info=findall(gcf,’type’,'line’);    
xdata1 = get(figure_info,’xdata’);   
ydata1 = get(figure_info,’ydata’);   
color1 = get(figure_info,’color’);   
subNum1 = length(xdata1);   

open(‘./test_2.fig’)   
figure_info=findall(gcf,’type’,'line’);    
xdata2 = get(figure_info,’xdata’);   
ydata2 = get(figure_info,’ydata’);   
color2 = get(figure_info,’color’);   
subNum2 = length(xdata2);   

open(‘./test_3.fig’)   
figure_info=findall(gcf,’type’,'line’);    
xdata3 = get(figure_info,’xdata’);   
ydata3 = get(figure_info,’ydata’);   
color3 = get(figure_info,’color’);   
subNum3 = length(xdata3);   

open(‘./test_4.fig’)   
figure_info=findall(gcf,’type’,'line’);    
xdata4 = get(figure_info,’xdata’);   
ydata4 = get(figure_info,’ydata’);   
color4 = get(figure_info,’color’);   
subNum4 = length(xdata4);   

%%   

subplot(2,2,1)   
for i=subNum1:-1:1   
    if length(xdata1{i})==1   
        break;   
    end   
    plot(xdata1{i},ydata1{i},‘.’,’color’,color1{i})   
    hold on;   
end   
title(‘(a). K-means (TF-IDF)’)   
set(gca,’xtick’,[]);   
set(gca,’ytick’,[]);   
% box off;   
% axis off;   
subplot(2,2,2)   
for i=subNum2:-1:1   
    if length(xdata2{i})==1   
        break;   
    end   
    plot(xdata2{i},ydata2{i},‘.’,’color’,color2{i})   
    hold on;   
end   
title(‘(b). Spectral Clustering (best)’)   
set(gca,’xtick’,[]);   
set(gca,’ytick’,[]);   
% box off;   
% axis off;   
subplot(2,2,3)   
for i=subNum3:-1:1   
    if length(xdata3{i})==1   
        break;   
    end   
    plot(xdata3{i},ydata3{i},‘.’,’color’,color3{i})   
    hold on;   
end   
title(‘(c). Average Embedding (TF)’)   
set(gca,’xtick’,[]);   
set(gca,’ytick’,[]);   
% box off;   
% axis off;   
subplot(2,2,4)   
for i=subNum4:-1:1   
    if length(xdata4{i})==1   
        break;   
    end   
    lineH(subNum4-i+1) = plot(xdata4{i},ydata4{i},‘.’,’color’,color4{i});   
    hold on;   
end   
title(‘(d). STCC’)   
set(gca,’xtick’,[]);   
set(gca,’ytick’,[]);   
% box off;   
% axis off;   
hL=legend(lineH,{’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′});   
newPosition = [0.4 0.4 0.2 0.2];   
newUnits = ’normalized’;   
set(hL,’Position’, newPosition,’Units’, newUnits);   

合并成单幅图像之后要做的另外一件美观的事情就是调整间距了。。。

1 代码实现

figure(‘Name’,’默认’);
subplot(2,2,1);
subplot(2,2,2);
subplot(2,2,3);
subplot(2,2,4);

figure(‘Name’,’紧凑’);
subplot(‘Position’,[0.02 0.65 0.3 0.3]);
subplot(‘Position’,[0.35 0.65 0.3 0.3]);
subplot(‘Position’,[0.02 0.3 0.3 0.3]);
subplot(‘Position’,[0.35 0.3 0.3 0.3]);
subplot(‘Position’,[left bottom width height]) creates an axes at the position specified by a four-element vector. left, bottom, width, and height are in normalized coordinates in the range from 0.0 to 1.
在由四个归一化坐标规定的位置上建立坐标轴。

2 手动调整
在图上的工具栏中点Tools,Align Distribute Tool,自己设定间距。
注意:1)需要先选中两幅图片,再调整间距;2)一定要用‘shift+click’选中待调整的两幅图片,不可以直接点
其实方式1 是一种非常赞的 版面设计方法,为了能够更加清楚明了的理解 那四个参数,[left,bottom,width,height]是什么意思,我画了一张图给大家,应该可以一目了然:
其中,第一幅图的参数为[0.02, 0.65, 0.3, 0.3]
这里写图片描述

猜你喜欢

转载自blog.csdn.net/H_____H/article/details/82349572