如何在子图中显示 Biograph 对象?
How can I display a Biograph object in a subplot?
我想在一些子图中绘制一些传记。请帮我完成这个任务。
有我的代码:
cm = [0 1 1 0 0;1 0 0 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 0 0];
cm2 = [0 1 1 0 1;1 0 1 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 1 0];
figure(18);
subplot(2,1,1);
view(biograph(cm));
subplot(2,1,2);
view(biograph(cm2));
代码:
h(1) = figure;
view(biograph(cm));
fig(1)=gcf; ax1=gca; % Figure and axes handles
c1 = get(fig(1), 'Children');
copyobj(c1,h(1)); % Copying the object to h(1)
h(2) = figure;
view(biograph(cm2));
fig(2)=gcf; ax2=gca; % Figure and axes handles
c2 = get(fig(2), 'Children');
copyobj(c2,h(2)); % Copying the object to h(2)
figure;
% Creating and getting handles of subplot axes
% Retrieving properties of children and copying to new parents and hiding the axes lines
s1 = subplot(1,2,1); bg1 = get(ax1,'children'); copyobj(bg1,s1); axis off;
s2 = subplot(1,2,2); bg2 = get(ax2,'children'); copyobj(bg2,s2); axis off;
close(fig); close(h); % Closing previously opened figures
输出:
这是对@ 的修改,应该适用于较新的 MATLAB 版本(其中 gcf
不再是 returns 人物传记的句柄):
function hF = q41124642()
cm = [0 1 1 0 0; 1 0 0 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 0 0];
cm2 = [0 1 1 0 1; 1 0 1 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 1 0];
% Look for biograph figures before and after ploting to know which figures to use
hBG{1} = findall( 0, 'Tag', 'BioGraphTool' ); % Before
view( biograph(cm) );
view( biograph(cm2) );
hBG{2} = findall( 0, 'Tag', 'BioGraphTool' ); % After
hBG = setdiff( hBG{2}, hBG{1} ); % (The difference contains the new figures)
% Create a new figure to hold the subplots:
hF = figure();
% Create and get handles of subplot axes:
s(1) = subplot(1,2,1);
s(2) = subplot(1,2,2);
% Retrieve children and copy to new parents, hiding the axes
IS_CHILD_AX = arrayfun( @(x)isa( x, 'matlab.graphics.axis.Axes' ), hBG(1).Children );
copyobj( hBG(1).Children(IS_CHILD_AX).Children, s(1) );
copyobj( hBG(2).Children(IS_CHILD_AX).Children, s(2) );
axis( s, 'off' );
% Close the biograph figures:
close(hBG);
备注:
- 在 R2018a 上测试。
- 我知道我应该通过跟随
biograph.view
进入 biograph.bggui
来寻找 'Tag','BioGraphTool'
,直到我找到所创建图形的一些识别特征。如果这不可用,我们会简单地向 findall
请求图表列表,两次,应用相同的差异逻辑。
我想在一些子图中绘制一些传记。请帮我完成这个任务。 有我的代码:
cm = [0 1 1 0 0;1 0 0 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 0 0];
cm2 = [0 1 1 0 1;1 0 1 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 1 0];
figure(18);
subplot(2,1,1);
view(biograph(cm));
subplot(2,1,2);
view(biograph(cm2));
代码:
h(1) = figure;
view(biograph(cm));
fig(1)=gcf; ax1=gca; % Figure and axes handles
c1 = get(fig(1), 'Children');
copyobj(c1,h(1)); % Copying the object to h(1)
h(2) = figure;
view(biograph(cm2));
fig(2)=gcf; ax2=gca; % Figure and axes handles
c2 = get(fig(2), 'Children');
copyobj(c2,h(2)); % Copying the object to h(2)
figure;
% Creating and getting handles of subplot axes
% Retrieving properties of children and copying to new parents and hiding the axes lines
s1 = subplot(1,2,1); bg1 = get(ax1,'children'); copyobj(bg1,s1); axis off;
s2 = subplot(1,2,2); bg2 = get(ax2,'children'); copyobj(bg2,s2); axis off;
close(fig); close(h); % Closing previously opened figures
输出:
这是对@gcf
不再是 returns 人物传记的句柄):
function hF = q41124642()
cm = [0 1 1 0 0; 1 0 0 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 0 0];
cm2 = [0 1 1 0 1; 1 0 1 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 1 0];
% Look for biograph figures before and after ploting to know which figures to use
hBG{1} = findall( 0, 'Tag', 'BioGraphTool' ); % Before
view( biograph(cm) );
view( biograph(cm2) );
hBG{2} = findall( 0, 'Tag', 'BioGraphTool' ); % After
hBG = setdiff( hBG{2}, hBG{1} ); % (The difference contains the new figures)
% Create a new figure to hold the subplots:
hF = figure();
% Create and get handles of subplot axes:
s(1) = subplot(1,2,1);
s(2) = subplot(1,2,2);
% Retrieve children and copy to new parents, hiding the axes
IS_CHILD_AX = arrayfun( @(x)isa( x, 'matlab.graphics.axis.Axes' ), hBG(1).Children );
copyobj( hBG(1).Children(IS_CHILD_AX).Children, s(1) );
copyobj( hBG(2).Children(IS_CHILD_AX).Children, s(2) );
axis( s, 'off' );
% Close the biograph figures:
close(hBG);
备注:
- 在 R2018a 上测试。
- 我知道我应该通过跟随
biograph.view
进入biograph.bggui
来寻找'Tag','BioGraphTool'
,直到我找到所创建图形的一些识别特征。如果这不可用,我们会简单地向findall
请求图表列表,两次,应用相同的差异逻辑。