MATLAB Answers

2D information to 1D colorplot

2 views (last 30 days)
marie deseyn
marie deseyn on 10 Dec 2019
Commented: Adam on 10 Dec 2019
I want to plot a line (which can be a thick line) in which I plot for every x the temperature as the color, so I want a 1D graph in which the color says the temperature on that place, is that possible?

  1 Comment

Adam
Adam on 10 Dec 2019
may help, if you are happy enough to have a surface object rather than a line object. It still looks like a line, just has surface properties so is a little less easy to do any further manipulations to if you need to.

Sign in to comment.

Answers (1)

darova
darova on 10 Dec 2019
Simple example
x = 0:10;
y = x.^2;
temp = rand(1,10); % temperature
cm = jet(10); % colormap
ind = 1+round(temp/max(temp)*9); % convert temperature to color index
figure(1)
hold on
for i = 1:length(x)-1
plot(x(i:i+1),y(i:i+1),'color',cm(ind(i),:))
end
hold off

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags