Heat Map - data interposed on geometry import
Afficher commentaires plus anciens
Hello,
I'm a complete novice of matlab (I'm learning)
Problem:
1) I have a 2D geometry of 290 x 260mm whereby there are 3 locations temperature is being monitored over time. There are time stamps in the data every 30 seconds (600+ time stamps) that measure the temperature ramp up, temperature hold, and temperature ramp down.
Data visualisation / expression:
I would like the data interposed on the 2D geometry where I can either at a specific timestamp, or be able to show the sequence over time in the plot.
Thank you!
Edit: Have added a sample of the data below.


5 commentaires
Torsten
le 25 Août 2026 à 13:53
Include a small test set of data so that we can experiment.
Mosef3000
le 25 Août 2026 à 14:09
Mosef3000
le 25 Août 2026 à 15:29
@Mosef3000, attach the data as a text file or simply paste text and format it with the code button so it can be read easily.
As for the visualization, you can plot the three lines with x as the time as datetime to show the evolution in time. If you want to add the color coding, you would need to use scatter instead to be able to set the colors on a pointwise basis as MATLAB doesn't support but a single color on a line. In that case, you might want to use both with 'hold on' to connect the dots.
OTOMH, I don't see any simple way to show the time evolution also in space; MATLAB doesn't have a builtin "4D" series of connected planes view and it's not clear to me how one would construct such. With only three essentially colinear points there isn't a way to draw a surface; one could alternativel for each time use plot3 to show the temperature
x=[60 145 190]; y=[60 130 200]; % coordinates from LL corner
z=[34.89 35.07 34.97;34.83 34.96 34.86]; % first two observations
plot3(x,y,z)
box on, grid on
view(-18,18)
is the first two points above. Ran out of time right now, but one could keep adding time points until it becomes too crowded and the rise and fall begin to occlude each other. One could also use 'hold on' and draw cross lines from the points over time.
On reflection, I guess one could do something similar with surface plot that would do the connection over time. Gotta' run, maybe @Torsten or somebody else will have a little more time to embellish later, but that hopefully will provide some ideas.
ADDENDUM
Sorry, had to run and didn't notice hadnt run the above to illusrate.
Back on the initial query regading overlaying the geometry, the heatmap specialty plot is not able to be modified effectively; it won't allow \hold on\ to even attempt to plot multiple time steps as planes. Nothing really comes to me as being really helpful here, sorry.
Mosef3000
le 26 Août 2026 à 13:08
Réponses (1)
hello
this is a simpler demo code , you can tweak it according to your data and display wishes
here a loop that goes through all data
if you simply want one specific time step , define the corresponding k time index to be displayed instead of the for loop
% Time vector
t = linspace(0,20,20);
% Example temperature variations (°C)
T1 = 20 + 10*sin(0.5*t);
T2 = 30 + 8*cos(0.4*t);
T3 = 25 + 12*sin(0.3*t + pi/4);
temps = [T1' T2' T3'];
% Temperature range for color scaling
Tmin = 0;
Tmax = 50;
% Colormap
cmap = jet(256);
figure('Color','w');
hold on;
colormap(cmap);
cb = colorbar;
cb.Label.String = 'Temperature (°C)';
clim([Tmin Tmax]);
%% geometric data
% outer rectangle
R_height = 260;
R_width = 290;
% Draw rectangle
rectangle('Position',[0 0 R_width R_height],'FaceColor','none','EdgeColor','k','LineWidth',1)
axis([0 300 0 300]);
axis off
daspect([1 1 1]) % like "axis equal" but preserves the geometry without MATLAB recentering the view (if it happens)
% smaller rectangles (TC1 to TC3)
tc1_pos = [0 0 145 260-130];
tc2_pos = [R_width-60 R_height-60 60 60];
tc3_pos = [0 60 60 R_height-60];
tc_pos = [tc1_pos; tc2_pos; tc3_pos];
for k = 1:length(t)
for i = 1:3
% Convert temperature to colormap index
idx = round(1 + (temps(k,i)-Tmin)/(Tmax-Tmin)*(size(cmap,1)-1));
idx = max(1,min(size(cmap,1),idx));
% Draw rectangle
rectangle('Position',tc_pos(i,:),'FaceColor',cmap(idx,:),'EdgeColor','k','LineWidth',1)
% Display temperature
tx = tc_pos(i,1) + 0.5*tc_pos(i,3);
ty = tc_pos(i,2) + 0.2*tc_pos(i,4);
text(tx,ty,sprintf('%.1f °C',temps(k,i)), 'HorizontalAlignment','center', 'FontSize',12);
end
title(sprintf('Time = %.1f s',t(k)));
pause(0.1)
end
10 commentaires
Mosef3000
le 26 Août 2026 à 13:17
Mathieu NOE
le 26 Août 2026 à 13:49
hello again
ok so the goal is to create 3 disks of radius 15 mm and these would have the color changing
the rest has to follow GlobalTCAvg data
again,if you coud share the data it would help - an image is not very helpful please use the paperclip button to share data as text or excel or mat file
tx
updated code :
% Time vector
t = linspace(0,20,20);
% Example temperature variations (°C)
Tc1 = 20 + 10*sin(0.5*t);
Tc2 = 30 + 8*cos(0.4*t);
Tc3 = 25 + 12*sin(0.3*t + pi/4);
GlobalTCAvg = 23 + 3*cos(0.3*t);
temps = [Tc1' Tc2' Tc3' GlobalTCAvg'];
% Temperature range for color scaling
Tmin = 0;
Tmax = 50;
% Colormap
cmap = jet(256);
figure('Color','w');
hold on;
axis([0 300 0 300]);
axis off
daspect([1 1 1]) % like "axis equal" but preserves the geometry without MATLAB recentering the view (if it happens)
colormap(cmap);
cb = colorbar;
cb.Label.String = 'Temperature (°C)';
clim([Tmin Tmax]);
%% geometric data
% outer rectangle
R_height = 260;
R_width = 290;
% (TC1 to TC3) disks centers coordinates x / y
tc1_pos = [145 130];
tc2_pos = [R_width-60 R_height-60];
tc3_pos = [60 60 ];
tc_pos = [tc1_pos; tc2_pos; tc3_pos];
theta = linspace(0,2*pi,100); % used to create disk plots
R = 15; % disks radius
for k = 1:length(t)
% background rectangle temperature animation
% Convert temperature to colormap index
idx = round(1 + (temps(k,4)-Tmin)/(Tmax-Tmin)*(size(cmap,1)-1));
idx = max(1,min(size(cmap,1),idx));
% Draw rectangle
rectangle('Position',[0 0 R_width R_height],'FaceColor',cmap(idx,:),'EdgeColor','k','LineWidth',1)
% disks temperature animation
for i = 1:3
% Convert temperature to colormap index
idx = round(1 + (temps(k,i)-Tmin)/(Tmax-Tmin)*(size(cmap,1)-1));
idx = max(1,min(size(cmap,1),idx));
% Draw disks
x = tc_pos(i,1) + R*cos(theta);
y = tc_pos(i,2) + R*sin(theta);
fill(x,y,cmap(idx,:),'EdgeColor','k');
% Display temperature
text(tc_pos(i,1),tc_pos(i,2),sprintf('%.1f °C',temps(k,i)), 'HorizontalAlignment','center', 'FontSize',12);
end
title(sprintf('Time = %.1f s',t(k)));
pause(0.1)
end
Mosef3000
le 26 Août 2026 à 14:23
Mathieu NOE
le 26 Août 2026 à 14:51
try this :
% read data
T = readtable("Sample1data_TC_Heatmap.xlsx");
% data is ordered as follows :
% Entry Timestamp TC-2 TC-1 TC-3 Mat-TC-9 TC-Setpoint GlobalTCAvg Temp Max Temp Min
% time conversion in string format
timeStr = datestr(T.Timestamp,'HH:MM:SS');
% temperature variations (°C)
temps = [T.TC_1 T.TC_2 T.TC_3 T.GlobalTCAvg]; % reorganized data array
% Temperature range for color scaling
Tmin = 0;
Tmax = 200;
% Colormap
cmap = jet(256);
figure('Color','w');
hold on;
axis([0 300 0 300]);
axis off
daspect([1 1 1]) % like "axis equal" but preserves the geometry without MATLAB recentering the view (if it happens)
colormap(cmap);
cb = colorbar;
cb.Label.String = 'Temperature (°C)';
clim([Tmin Tmax]);
%% geometric data
% outer rectangle
R_height = 260;
R_width = 290;
% (TC1 to TC3) disks centers coordinates x / y
tc1_pos = [145 130];
tc2_pos = [R_width-60 R_height-60];
tc3_pos = [60 60 ];
tc_pos = [tc1_pos; tc2_pos; tc3_pos];
theta = linspace(0,2*pi,100); % used to create disk plots
R = 15; % disks radius
for k = 1:size(T,1)
% background rectangle temperature animation
% Convert temperature to colormap index
idx = round(1 + (temps(k,4)-Tmin)/(Tmax-Tmin)*(size(cmap,1)-1));
idx = max(1,min(size(cmap,1),idx));
% Draw rectangle
rectangle('Position',[0 0 R_width R_height],'FaceColor',cmap(idx,:),'EdgeColor','k','LineWidth',1)
% disks temperature animation
for i = 1:3
% Convert temperature to colormap index
idx = round(1 + (temps(k,i)-Tmin)/(Tmax-Tmin)*(size(cmap,1)-1));
idx = max(1,min(size(cmap,1),idx));
% Draw disks
x = tc_pos(i,1) + R*cos(theta);
y = tc_pos(i,2) + R*sin(theta);
fill(x,y,cmap(idx,:),'EdgeColor','k');
% Display temperature
text(tc_pos(i,1),tc_pos(i,2),sprintf('%.1f °C',temps(k,i)), 'HorizontalAlignment','center', 'FontSize',10,'Color','k');
end
current_time = T(k,:).Timestamp;
title(['Time = ' timeStr(k,:)]);
pause(0.1)
end
Mathieu NOE
le 27 Août 2026 à 9:56
hello again
did you try the code ? is it what you exected ?
all the best
Mosef3000
le 27 Août 2026 à 12:39
Mosef3000
le 31 Août 2026 à 12:42
Mathieu NOE
le 31 Août 2026 à 13:17
hello again
can you try with the older syntax :
caxis([Tmin Tmax]); % (instead of clim([Tmin Tmax]);)
@Mosef3000 The warning is that in
T = readtable("Sample1data_TC_Heatmap.xlsx");
% data is ordered as follows :
% Entry Timestamp TC-2 TC-1 TC-3 Mat-TC-9 TC-Setpoint GlobalTCAvg Temp Max Tem
the variables in the header line in the file are invalid as they are as MATLAB variable names because of the embedded minus signs; readtable and friends handle this internally by converting the minus signs to underscores but provide a warning of having done so. You see the result in @Mathieu NOE's code line
temps = [T.TC_1 T.TC_2 T.TC_3 T.GlobalTCAvg]; % reorganized data array
where he used the converted variable names. You can either ignore the warning or add a line with the warning function to suppress it or use the named parameter
'VariableNamingRule','preserve'
to use the names as are in the header row. If you do this, you'll have to treat them with the syntax of using a string representation T.("TC-1"), etc., instead which preserves the names as were given but detracts significantly from the use convenience.
The takeaway might be that if one has control over the creation of the input file to use a naming convention for the variables that is consistent with MATLAB variable name rules without the extension of handling special characters.
Catégories
En savoir plus sur Geographic Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






