Plotting Data as Heatmap/Bar Graph Hybrid?

조회 수: 10 (최근 30일)
Alexander
Alexander 2025년 3월 8일
답변: Sulaymon Eshkabilov 2025년 3월 8일
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!

채택된 답변

Voss
Voss 2025년 3월 8일
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()
  댓글 수: 2
Alexander
Alexander 2025년 3월 8일
That is exactly what I'm looking for, thank you!
Voss
Voss 2025년 3월 8일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2025년 3월 8일
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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by