How can I create a heatmap?
    18 views (last 30 days)
  
       Show older comments
    
    Sanley Guerrier
 on 28 Jul 2023
  
    
    
    
    
    Commented: Sanley Guerrier
 on 31 Jul 2023
            Can someone help with to create a heatmap for this data? 
I tried with these commands but it didn't work. Thank you!
xvar = T.Xft;
yvar = T.Yft;
Temp = T(:,4:end);
gridres = 100 ;
xs = linspace(min(xvar),max(xvar),gridres) ;
ys = linspace(min(yvar),max(yvar),gridres) ;
[xq,yq]=meshgrid(xs,ys) ;
InterpolatedTemp = griddata(xvar,yvar,Temp,xq,yq) ;
hmap_above = pcolor(xq,yq,InterpolatedTemp);
hmap_above.EdgeColor = [.5 .5 .5] ; 
colorbar
colormap jet
title('heatmap')
shading interp
5 Comments
  Jon
      
 on 28 Jul 2023
				Please provide a description of the data in T.xlsx, and what you really want plotted in your "heat map". 
Looking at the data, I see that your data X (ft), and Y (ft), do not provide a grid, or even a scattered sampling of the x,y plane. Instead the x and y points all fall along a line. There are multiple columns of T data. If so, the heat map could only plot the data for one of those columns. 
At the moment even if you just chose one of those columns, you still couldn't provide a map of temperatures across the x-y plane as you only have data for points along one line in this plane.
Accepted Answer
  Cris LaPierre
    
      
 on 28 Jul 2023
        
      Edited: Cris LaPierre
    
      
 on 28 Jul 2023
  
      Do you need to preserve the shape of the road in your heatmap? If not, the easiest approach is to just create a heatmap using the T0-T6 columns.
T = readtable("T.xlsx","VariableNamingRule","preserve");
heatmap(T{:,["T" + (0:6)]})
Another way to do this might be the following
newT = stack(T,["T" + (0:6)],"NewDataVariableName","Value");
heatmap(newT,"Value_Indicator","Distance from CR29 (ft)","ColorVariable","Value")
9 Comments
  Cris LaPierre
    
      
 on 31 Jul 2023
				The problem is that you have a 4D data set (X,Y,T,v), or 29x29x7x1. For each (x,y) pair, you have 7 values. A surface plot expects one value per point.
T = readtable("T.xlsx","VariableNamingRule","preserve");
surf(categorical(["T"+(0:6)]),T.("Distance from CR29 (ft)"),T{:,["T"+(0:6)]})
colorbar
When you have more than 3 dimensions, you need to get creative, using marker style, color, size, linestyle, etc to convey the higher dimensions.
newT = stack(T,["T" + (0:6)],"NewDataVariableName","Value");
grps = unique(newT.Value_Indicator);
for g = 1:length(grps)
    ind = ismember(newT.Value_Indicator,grps(g));
    scatter3(newT{ind,"X (ft)"},newT{ind,"Y (ft)"},newT.Value(ind),'filled')
    hold on
end
hold off
legend(grps)
More Answers (0)
See Also
Categories
				Find more on Color and Styling 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!









