Ploting heatmaps in function of time
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello,
I have search a solution for my problem but didn't find any that suited my problem.
Basically, I have a 3D matrix (18x17x2000) representing heatmap of a sample on the 2000 frames of the measurement. I would like to plot it all but with a slider or a cursor or whatever that could allow me to chose which frame I want to display, allowing me to easily go through my data.
I tried the VideoWriter tool but it gives really blurry and not convenient result. The goal is to keep the heatmap representation.
Thank you for your help,
採用された回答
This demo produces a heatmap with random data and a slider that controls which slice of the 3rd dimension of data to plot.
Demo based on a similar solution for bar plots but uses a ValueChangingFcn to update the heatmap and title as the slider changes instead of a ValueChangedFcn which is evoked after making a change to the slider.
data = rand(20,20,2000); % data with size n*m*k
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
heatObj = heatmap(uip, data(:,:,1));
title(heatObj, 'Frame #1');
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', [1, 200:200:n], ...
'MinorTicks', []);
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj};
function sliderChangingFcn(~,event,data,heatObj)
% Update heatmap and title with new selection of data
value = round(event.Value);
heatObj.ColorData = data(:,:,value);
heatObj.Title = sprintf('Frame #%d',value);
end
Tip: set clim so the colorbar limits do not jump around as the heatmap data are updated. This is seen in the GIF below.

8 件のコメント
Julien Maxime
2022 年 9 月 27 日
It is exactly what I needed, thank you very much. Hoping this can help others with the same issue as mine.
Julien Maxime
2022 年 9 月 27 日
I have another related question. Do you think it is possible to make the heatmap change as the cursors is moving and not only when the cursos is release ?
Adam Danz
2022 年 9 月 27 日
Try replacing the valueChangedFcn with the valueChangingFcn.
Julien Maxime
2022 年 9 月 27 日
編集済み: Torsten
2022 年 9 月 27 日
Thank you very much for your help really. I dare ask one last question. Here is the relevant code part of the plot:
data = M;
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
hh = heatmap(uip, data(:,:,1),'Colormap', hsv,'CellLabelColor', 'none','ColorLimits', [-360 50]);
title(hh, 'Electrode Fluorescence Heatmap - Frame #1');
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, uip, data};
function sliderChangingFcn(h,~,uip,data)
value = round(h.value);
hh = heatmap(uip,data(:,:,Value), 'Colormap', hsv, 'CellLabelColor', 'none', 'ColorLimits', [-360 50]);
title(hh, sprintf('Electrode Fluorescence Heatmap - Frame #%s',num2str(value)))
end
However, when i slide the cursor it changes the plot one time during the sliding but then stays and lag/block on this last plot. I have to drop it and move it again to diplay a new plot again. I found this guy who had a similar problem but I don't know how to adapt it to my situation: https://www.mathworks.com/matlabcentral/answers/521185-how-to-continuously-change-the-plotted-data-according-to-the-value-obtained-from-a-uislider-compon
Can you help me ?
Thank you very much.
Adam Danz
2022 年 9 月 27 日
I've updated my answer to use a ValueChangingFcn. The updated answer also updates the existing heatmap rather than recreating it which is much more efficient.
Julien Maxime
2022 年 9 月 28 日
Thank you it is perfect!
Patricia Darling
2025 年 7 月 29 日
編集済み: Patricia Darling
2025 年 7 月 29 日
Where would I embed clim in the code above. I tried making it stand alone in the main script and in the function and it doesn't seem to be impacting anything.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
参考
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)
