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 comentarios

Chetan Bhavsar
Chetan Bhavsar el 28 de Jul. de 2023
What Error you are facing?
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
It says:
Error using griddata
invalid input arguments.
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
Do you think if I use latitude and longitude instead of using X and Y would give a better heat map plot?
I am not sure what to use, the table below has distance, X and Y coordinates, also latitude and londitude.
Jon
Jon el 28 de Jul. de 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.
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
Each point (X, Y) coordinate has a series of thermal values from T0 to T6. T0 to T6 are measured a long a straight line which is the width of a road and the column "distance" is the length of the road.
I would like to visualize the data to see the change in temperature a long the road.
Thank you!

Iniciar sesión para comentar.

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 28 de Jul. de 2023
Editada: Cris LaPierre el 28 de Jul. de 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 comentarios

Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
Thank you. The second way looks more convincing to me. Is there a way to change the color of the map so that the difference between the temperature becomes more obvious.
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
When I tried these lines of commands the result is different than yours. I don't what's wrong with matlab.
T = readtable("T.xlsx","VariableNamingRule","preserve");
heatmap(T{:,["T" + (0:6)]})
Are you using the same dataset you posted here?
Yes, use the colormap command to set your desired colormap.
T = readtable("T.xlsx","VariableNamingRule","preserve");
newT = stack(T,["T" + (0:6)],"NewDataVariableName","Value");
heatmap(newT,"Value_Indicator","Distance from CR29 (ft)","ColorVariable","Value")
colormap jet
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
It was because I did it in live script. I am so sorry.
Cris LaPierre
Cris LaPierre el 28 de Jul. de 2023
I am also using a live script. There shouldn't be any difference. If there is, try inserting a figure command before your heatmap command.
Sanley Guerrier
Sanley Guerrier el 28 de Jul. de 2023
I hab multiple live scripts opened and I closed them. Now, it's working fine. Thanks for helping!
Sanley Guerrier
Sanley Guerrier el 31 de Jul. de 2023
Hi Cris LaPiere, last time your help was very useful.
With the same data you helped with last time I wanted to plot a 2D surface with the X , Y coordinates and the temperatures. Could you please help me?
I want to plot all column temperatures in one figure.
N.B: the data I used in the following code is saved in a CSV file.
Thank you!
filename='T.csv';
df = csvread(filename,1,0);%skip 1 header line
X_df=df(:,2);
Y_df=df(:,3);
T0=df(:,6);% when I tried T_df = df(:, 6:end) it gave an error for line 11
%create grid
[x,~,xi]=unique(X_df);
[y,~,yi]=unique(Y_df);
subs=[xi yi];
val=T0;
M=accumarray(subs,val,[],[],NaN);
[X,Y]=ndgrid(x,y);
%create plot
figure(1),clf(1)
surf(X,Y,M)
view(0,90),xlabel('x(ft)'),ylabel('y(ft)'), title("EB Morning Run for T0")
colorbar
shading interp
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.
If the heatmap approach worked for you, then I'd do something similar using surf.
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)
Sanley Guerrier
Sanley Guerrier el 31 de Jul. de 2023
Appriciate it Cris!
I think I got now. Thanks for the precision.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Jul. de 2023

Comentada:

el 31 de Jul. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by