Custom color of a line based on the value of the 3rd parameter

조회 수: 3(최근 30일)
SS 2021년 9월 30일
편집: DGM 2021년 9월 30일
Hi. I am plotting a line using X and Y, I want the line to appear as a continuous line colored based on the value of another 3rd parameter T. T holds the velocity information of the particle at different positions along its trajectory.
For inatance,
X=[1,2,3,4,5,6,7,8,9,10];
Y=[2,4,6,8,10,12,14,16,18,20];
T=[10,10,10,20,30,50,10,30,10,100];
I want a straight line using X and Y, the color of the line should be based on the values of T.
Any help is appreciated.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM 2021년 9월 30일
편집: DGM 2021년 9월 30일
There are a couple ways to do this. Using surf() seems to be the better way in general for lines.
x = [1,2,3,4,5,6,7,8,9,10];
y = [2,4,6,8,10,12,14,16,18,20];
t = [10,10,10,20,30,50,10,30,10,100];
h = surf([x(:) x(:)],[y(:) y(:)],[t(:) t(:)]);
set(h,'facecolor','none','edgecolor','interp');
set(h,'linewidth',3); % make it fat so it's easier to demonstrate
view(2); % only show 2-D view
colormap(jet(256)); % or pick whatever map you want
colorbar
In my opinion, it's always difficult to read these types of plots without making the line rather thick. Discerning small local color differences against a broad white background is difficult. Compare against the same color against inverted colors:
Then again, using an inverted background isn't really practical for a lot of output requirements. Just a thought.
SS 2021년 9월 30일
Thank you.

댓글을 달려면 로그인하십시오.

범주

Find more on Red 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!

Translated by