Help to create a continuous surface heatmap

Dear experts -
I want to create a continuous 1D surface heatmap for every data point, with Distance (ft) in the X-direction and Temperature in the Y-direction. I have no idea how to do it. Please, can someone helps me with that.
Here I attached a sample of my data.
Thank you!

1 件のコメント

Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
Maybe a colormap might work better if there is a difference between colormap and heat map.

サインインしてコメントする。

 採用された回答

Voss
Voss 2024 年 8 月 19 日

0 投票

I'm not sure what a 1D surface looks like.
If Temperature is in the Y-direction, what variable should be used for the color of the surface?
Here I use all T0-T14 as the color data, Distance as X, and 1 through 15 as Y. Adjust as necessary.
data = readtable('data.xlsx','VariableNamingRule','preserve');
T = data{:,"T"+(0:14)};
X = data{:,"Distance (ft)"};
Y = 1:15;
surface(X,Y,T.')
axis tight
xlabel("Distance (ft)")
ylabel("1 - 15")
cb = colorbar();
cb.Label.String = "Temperature";

13 件のコメント

Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
Thank you, Voss.
That is exactly what I want. Is it possible to get ride of the grid?
My actual data is T0 to T300 and distance is "11000 ft". Is is possible to create the surface for that length without concentrate the length so that I can visualize the plot?
Voss
Voss 2024 年 8 月 19 日
編集済み: Voss 2024 年 8 月 19 日
You're welcome!
To get rid of the grid, use
surface(X,Y,T.','EdgeColor','none')
I'm not sure I understand the second question. What do you mean by "without concentrate the length"? Do you mean to use a constant grid spacing in the x-direction, not using the Distance variable, just using equally-spaced grids between 0 and 11000 ft? If so, you can create a new X for plotting the surface using linspace(), as shown below (I also generalized the value of Y to work for any size data table):
data = readtable('data.xlsx','VariableNamingRule','preserve');
T = data{:,"T"+(0:14)};
X = linspace(0,max(data{:,"Distance (ft)"}),size(T,1));
Y = 1:size(T,2);
surface(X,Y,T.','EdgeColor','none')
axis tight
xlabel("Distance (ft)")
ylabel(sprintf("T0 - T%d",numel(Y)-1))
cb = colorbar();
cb.Label.String = "Temperature";
Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
I used your code and updated it for my data. Attached is a picture of the result.
I would like to adjust the size of the figure to see the temperature differential.
please, see my attachment.
Thank you.
clear; close all; clc;
data = readtable('data.xlsx','VariableNamingRule','preserve');
T = data{:,"T"+(0:319)};
X = data{:,"Distance fr(ft)"};
Y = 1:320;
surface(X,Y,T.')
axis tight
xlabel("Distance (ft)")
ylabel("T0 - T319")
cb = colorbar();
cb.Label.String = "Temperature";
Voss
Voss 2024 年 8 月 19 日
You left out the 'EdgeColor','none' to remove the grid lines.
surface(X,Y,T.','EdgeColor','none')
Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
This figure is from you update code. Because the data is to big I cannot see the temperature differential.
Voss
Voss 2024 年 8 月 19 日
If you want (or don't mind having) an equally-spaced grid in the x-direction, you can use an image instead of a surface, which may or may not help.
data = readtable('data.xlsx','VariableNamingRule','preserve');
T = data{:,"T"+(0:14)};
X = [0 max(data{:,"Distance (ft)"})];
Y = [0 size(T,2)-1];
imagesc(X,Y,T.')
axis xy
xlabel("Distance (ft)")
ylabel(sprintf("T0 - T%d",Y(2)))
cb = colorbar();
cb.Label.String = "Temperature";
Try that on your data and see how it looks.
Otherwise, the options are to increase the figure size and/or adjust the xlim/ylim to zoom in.
Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
That doesn't help. I wonder if changing the colorbar would make a difference.
Can you refer me to some options to increase the figure size (width)?
Thank you.
Voss
Voss 2024 年 8 月 19 日
Choosing a different colormap might help.
To change the figure size, you can click the figure window's maximize button, or drag an edge of the figure window, or set the figure's Position programmatically, e.g.:
f = gcf();
f.Position(3) = 2000; % set the current figure's width to 2000
% (pixel Units assumed, which is the default default)
Voss
Voss 2024 年 8 月 19 日
Another option would be to set the colormap limits, e.g., since the temperatures seem to be almost all in the range -20 to 0
clim([-20 0]) % or caxis([-20 0]) in R2021b or earlier
which should allow you to see the variation at the expense of "maxing out" temperature values outside that range.
Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
I use colormap jet and set the width to 2000, it increases the figure size but colormap stays blue.
T = data{:,"T"+(0:319)};
X = linspace(0,max(data{:,"Distance from CR29 (ft)"}),size(T,1));
Y = 1:size(T,2);
h=surface(X,Y,T.','EdgeColor','none');
ax = ancestor(h, 'axes');
ax.XAxis.Exponent = 0;
xtickformat('%.0f')
axis tight
xlabel("Distance from CR29 (ft)")
ylabel(sprintf("T0 - T%d",numel(Y)-1))
cb = colorbar();
cb.Label.String = "Temperature";
colormap jet;
f = gcf();
f.Position(3) = 2000;
Voss
Voss 2024 年 8 月 19 日
Another option would be to set the colormap limits, e.g., since the temperatures seem to be almost all in the range -20 to 0
clim([-20 0]) % or caxis([-20 0]) in R2021b or earlier
which should allow you to see the variation at the expense of "maxing out" temperature values outside that range.
Sanley Guerrier
Sanley Guerrier 2024 年 8 月 19 日
I set clim([-20 0]). Now it works :)
Thanks alot Voss.
Voss
Voss 2024 年 8 月 19 日
Excellent!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

タグ

質問済み:

2024 年 8 月 19 日

コメント済み:

2024 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by