How can I create a patch between two graphs?

13 ビュー (過去 30 日間)
Sim
Sim 2022 年 2 月 17 日
コメント済み: Voss 2022 年 2 月 18 日
How can I create a patch between two graphs ?
clear all;clc;
s = [1 2 3 4];
t = [2 3 4 5];
x = [0 1 2 2 4];
y = [0 0 0 0 0];
z = [1 1 2 3 3];
G = graph(s,t);
G.Nodes.X = x'; G.Nodes.Y = y'; G.Nodes.Z = z';
hold on
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y + 2,'ZData',G.Nodes.Z)
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y,'ZData',G.Nodes.Z)
hold off
view(-45,15)
My expected result would be something like this:

採用された回答

Voss
Voss 2022 年 2 月 17 日
clear all;clc;
s = [1 2 3 4];
t = [2 3 4 5];
x = [0 1 2 2 4];
y = [0 0 0 0 0];
z = [1 1 2 3 3];
G = graph(s,t);
G.Nodes.X = x'; G.Nodes.Y = y'; G.Nodes.Z = z';
hold on
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y + 2,'ZData',G.Nodes.Z)
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y,'ZData',G.Nodes.Z)
hold off
% use indexing into G.Nodes.X,Y,Z. each column of idx corresponds to a
% patch face.
idx = (1:numel(G.Nodes.X)-1)+[0; 1; 1; 0]
idx = 4×4
1 2 3 4 2 3 4 5 2 3 4 5 1 2 3 4
p_x = G.Nodes.X(idx);
p_y = G.Nodes.Y(idx);
p_y([3 4],:) = p_y([3 4],:)+2;
p_z = G.Nodes.Z(idx);
patch('XData',p_x,'YData',p_y,'ZData',p_z,'FaceColor','y','FaceAlpha',0.5);
view(-45,15)
  2 件のコメント
Sim
Sim 2022 年 2 月 18 日
編集済み: Sim 2022 年 2 月 18 日
Thanks a lot @_! I think we got the same idea, but yours is way much cooler and efficient !! Many thanks :)
Voss
Voss 2022 年 2 月 18 日
You're welcome! Glad I could help!

サインインしてコメントする。

その他の回答 (1 件)

Sim
Sim 2022 年 2 月 17 日
編集済み: Sim 2022 年 2 月 17 日
I think found the way:
patch([x fliplr(x)], [y fliplr(y+2)], [z fliplr(z)], 'g')
Everything together will be:
clear all;clc;
s = [1 2 3 4];
t = [2 3 4 5];
x = [0 1 2 2 4];
y = [0 0 0 0 0];
z = [1 1 2 3 3];
G = graph(s,t);
G.Nodes.X = x'; G.Nodes.Y = y'; G.Nodes.Z = z';
hold on
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y + 2,'ZData',G.Nodes.Z)
plot(G,'XData',G.Nodes.X,'YData',G.Nodes.Y,'ZData',G.Nodes.Z)
patch([x fliplr(x)], [y fliplr(y+2)], [z fliplr(z)], 'g')
hold off
view(-45,15)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by