Associate colormap to temperature of plot x,y data

7 views (last 30 days)
Hello,
I'm trying to find a way to map temperature (degC) to a color map, such as 'jet', so that when I plot a x,y graph, I can plot the color of that line to represent the temperature of the data
for example, my temperature range would be -50degC to +150degC.
on one figure plot, I could plot three lines of measurement data, one taken at cold (-30degC), another at room temperature (+23degC), and the last at hot (+75degC). The colors of the plot lines would be blue, green, and red.
I would use some kind of lookup to the color map, based on the known temperature of the data (data file includes temperature in the header).
this would be a 2D plot, so instead of e.g. figure;plot(x,y,'k-');hold on;plot(a,b,'r-') it would be
% lookup temperature of dataset x,y and dataset a,b tempxy = -15; tempab = +45; % find this temperature and associated a color to them colorxy = [0 0 0.789]; colorab = [0 0.456 1]; figure;plot(x,y,'color',colorxy) %etc
Can anyone please advise on the best way to do this?
Thank you.

Accepted Answer

Phil Newman
Phil Newman on 26 Apr 2016
HI,
this was my final solution.
colormap = jet; % or type out values of jet into colormap
x = 1:0.1:20; % dummy dataset
y = sin(x);
newrange = [1:64/100:64]'; % temperature range of -25degC to +75degC = 100 points
oldrange = [1:1:64]';
colormapinterp = interp1(oldrange,colormap,newrange); %Vq = interp1(X,V,Xq);
temprange = [-25:1:75];
temp1 = -15;
temp2 = 25;
temp3 = 65;
k1 = find(temprange==temp1); % find index of each temperature
k2 = find(temprange==temp2);
k3 = find(temprange==temp3);
color1 = colormapinterp(k1,:,:); % find color based on index value
color2 = colormapinterp(k2,:,:);
color3= colormapinterp(k3,:,:);
figure
plot(x,y,'Color',color1)
hold on
plot(x,10*y,'Color',color2)
hold on
plot(x,5*y,'Color',color3)

More Answers (2)

Image Analyst
Image Analyst on 10 Apr 2016
Use caxis().
  1 Comment
Phil Newman
Phil Newman on 11 Apr 2016
Hi,
thanks for your response.
I'm not sure that caxis() will help me here, as this seems to be for mesh type plots?
I am only using line data in a x,y format. each line is plotted individually on the same graph, and the color of the line would correspond to the temperature associated with the data.
Thanks, Phil

Sign in to comment.


Phil Newman
Phil Newman on 11 Apr 2016
Hi,
thanks for your response.
I'm not sure that caxis() will help me here, as this seems to be for mesh type plots?
I am only using line data in a x,y format. each line is plotted individually on the same graph, and the color of the line would correspond to the temperature associated with the data.
Thanks, Phil

Community Treasure Hunt

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

Start Hunting!