Help to create a continuous surface heatmap
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
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";
You left out the 'EdgeColor','none' to remove the grid lines.
surface(X,Y,T.','EdgeColor','none')
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.
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.
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)
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.
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;
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.
I set clim([-20 0]). Now it works :)
Thanks alot Voss.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
