Uistack with a Graph and Subgraphs (GraphPlot)
Introduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlotIntroduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot Introduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot uistack, graph, subgraph, graphplot, visual stack MATLAB Answers — New Questions