線形2次元plotのグラデーション
53 views (last 30 days)
Show older comments
plot(x1,y1)
hold on
plot(x2,y2)
plot(x3,y3)
・
・
・
plot(xn,yn)
このように幾つかのグラフを同時に描くとき、1~nまでグラデーションで表すにはどうしたら良いでしょうか?
0 Comments
Accepted Answer
Atsushi Ueno
on 16 Mar 2022
>このように幾つかのグラフを同時に描くとき、1~nまでグラデーションで表すにはどうしたら良いでしょうか?
colororder関数で「色の順序」を定義すれば、plot関数で指定しなくても指定色を順に選んで描画してくれます。
n = 100; d = 0.1;
x = repmat((0:d:2*pi)',1,n); % 0~2πの列をn行重ねた行列
y = sin(x) + (d:d:n*d); % 上記のsinを取りy軸方向にちょっとずつずらす
colororder(parula(n)); % 事前定義されたカラーマップ"parula”を使用する例
% colororder(repmat((d:d:n*d)'./(n*d),1,3)) % 独自に作るグラデーション色の例
plot(x,y,'LineWidth',2); % 線の太さ1だと隙間が出来る。太さ2だと綺麗になる
2 Comments
Atsushi Ueno
on 16 Mar 2022
Edited: Atsushi Ueno
on 16 Mar 2022
for文で1ラインずつ描画する場合も同様です。下記の様にすれば上記回答と同様に動作します。
figure; hold on
colororder(parula(n));
for i = 1:size(x,2)
plot(x(:,i),y(:,i));
end
More Answers (0)
See Also
Categories
Find more on 2 次元および 3 次元プロット in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!