How to plot single colorful line?

1 次查看(过去 30 天)
Iam trying to plot a single line graph varaying colororder depending on the intensity increse.
x=[1 2 3 4 5 6 ];
y=[1 2 3 4 5 6 ];
plot(x,y), colororder(jet)
expecting to color change over line. Thank you.

采纳的回答

KSSV
KSSV 2023-6-20
x=[1 2 3 4 5 6 ];
y=[1 2 3 4 5 6 ];
z = zeros(size(x));
col = x; % This is the color, vary with x in this case.
surface([x;x],[y;y],[z;z],[col;col],...
'facecol','no',...
'edgecol','interp',...
'linew',2);

更多回答(1 个)

DGM
DGM 2023-6-20
编辑:DGM 2023-6-20
This can't be done with a single line object. It can be done with multiple line objects or with patch objects. This thread has examples of both.

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by