plotを使用してグ​ラフの色をデータに応​じて変更する方法

29 views (last 30 days)
yuto tamura
yuto tamura on 10 Apr 2020
Answered: yuto tamura on 11 Apr 2020
line関数を使用して2点を結ぶ直線を引き, それぞれの対応する値により直線の色を変更する方法がわかりません.
scatter関数のように値でグラフの色を変更できる方法を知りたいです.
例)
x y  番号
1 1 1
5 4 2
10 5 3
20 10 4
のようなデータの組があり,
それぞれの点を結ぶ組み合わせで対応する値がありその値により直線の色を変更するプログラムがわかりません.
組み合わせ   値
1-2 0.1
1-3 0.7
1-4 0.01
1-5 0.007
すみませんが, よろしくお願いいたします.

Accepted Answer

Akira Agata
Akira Agata on 11 Apr 2020
以下のように、グラフオブジェクトを構築・可視化する方法はいかがでしょうか?
% データ点の(x,y)座標
x = [1,5,10,20];
y = [1,4,5,10];
% Edgeの始点(s),終点(t),重み(w)
% ※注:組み合わせのうち "1-5" については対応するデータ点がないため除去しました。
s = [1,1,1]';
t = [2,3,4]';
w = [0.1,0.7,0.01]';
% グラフを構築
G = graph(s,t);
% 可視化
figure
plot(G,'XData',x,'YData',y,'EdgeCData',w,'LineWidth',2,'MarkerSize',8);
colorbar

More Answers (1)

yuto tamura
yuto tamura on 11 Apr 2020
ありがとうございます.
無事グラフにすることが出来ました.
本当にありがとうございました.

Categories

Find more on 2 次元および 3 次元プロット in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!