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
2024 年 8 月 19 日
Maybe a colormap might work better if there is a difference between colormap and heat map.
採用された回答
Voss
2024 年 8 月 19 日
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
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?
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";

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
2024 年 8 月 19 日
You left out the 'EdgeColor','none' to remove the grid lines.
surface(X,Y,T.','EdgeColor','none')
Sanley Guerrier
2024 年 8 月 19 日
This figure is from you update code. Because the data is to big I cannot see the temperature differential.
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
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
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
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
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
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
2024 年 8 月 19 日
I set clim([-20 0]). Now it works :)
Thanks alot Voss.
Voss
2024 年 8 月 19 日
Excellent!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Color and Styling についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
