Plotting Data as Heatmap/Bar Graph Hybrid?

8 views (last 30 days)
Hey so I'm plotting some temperature data from thermistors along a body to present at a research symposium, and I want to try and represent it in a way that represents what the temperature was at the specified point along the body. Using just normal pot(), the data looks like this:
what I want to do is make essentially a horizontal bar graph, where the y-axis is each of the lines in the plot above, the x-axis is time, and the color of the bar at that point in time is heatmapped to the value of that line at that time. I had tried just using heatmap() with the input data but it spit out a chart that was taken up by the division lines (there's ~22k samples for each sensor) so you couldn't actually see any of the colors.
in short, transforming the plot above > desired:
x-axis > x-axis
legend > y-axis
y-axis > bar color at x
thanks!

Accepted Answer

Voss
Voss on 8 Mar 2025
Something like this?
% generate t and data
Nt = 22e3;
Nc = 8;
t = linspace(0,1,Nt).';
data = zeros(Nt,Nc);
t0 = 0.15;
idx = t > t0;
data(idx,:) = (t(idx)-t0).^0.25.*exp(1.5*(t0-t(idx)))*2.*(Nc:-1:1)/Nc;
whos t data
Name Size Bytes Class Attributes data 22000x8 1408000 double t 22000x1 176000 double
% line plot for reference
figure()
plot(t,data)
legend()
% surface plot
[Nt,Nc] = size(data);
assert(numel(t) == Nt)
X = t(:).*ones(1,Nc+1);
Y = (1:Nc+1).*ones(Nt,1);
C = data(:,[1:end end]);
figure()
surface(X,Y,C,'EdgeColor','none')
set(gca(), ...
'YDir','reverse', ...
'YLim',[1 Nc+1], ...
'YTick',(1:Nc)+0.5, ...
'YTickLabel',"data"+(1:Nc))
colormap(jet())
colorbar()

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 8 Mar 2025
Here is one example code how to get such plot figure:
D = readmatrix("SENSOR_Values.txt");
Time = 0:1:height(D)-1;
% Use y-values for Color mapping
Color1 = D(:,1);
Color2 = D(:,2);
Color3 = D(:,3);
hold on
for ii = 1:width(D);
scatter(Time, D(:, ii), 20, D(:,ii), 'filled'); % 20 is the marker size
end
colormap(jet); % Choose a colormap
colorbar; % Display colorbar to show the mapping
xlabel('Time, [s]');
ylabel('Temperature, [F]');
title('Colormap Based on Temperature Values');
hold off

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!