How to insert a line over a heatmap using code?

How can I insert a line over a heatmap in my code? I would rather not use the figure tools manually because I have to do multiple lines.

回答 (3 件)

Robert U
Robert U 2018 年 6 月 15 日

1 投票

Hi Samantha Clayton:
Since I do not know your code I can only demonstrate in the following example how to draw a vertical and a horizontal line into a contourf-plot (assuming you mean something like that).
Z = peaks(20);
ah = axes;
h = contourf(Z,10,'Parent',ah);
hold(ah,'on')
plot(ah,[0 25],[10 10],'white') % horizontal line
plot(ah,[10 10],[0 25],'white') % vertical line
ah.XLim = [2 20];
ah.YLim = [2 20];
There is a HeatMap-Command in Bioinformatics toolbox, so I do not know whether same strategy is working for that.
Kind regards,
Robert

3 件のコメント

Walter Roberson
Walter Roberson 2018 年 6 月 15 日
New MATLAB also have heatmap().
Osama El-Ghonimy
Osama El-Ghonimy 2018 年 12 月 27 日
Not working with Heatmap finction in MATLAB 2018b
Jeff Miller
Jeff Miller 2022 年 9 月 1 日

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

Robert U
Robert U 2022 年 9 月 5 日

1 投票

Since the thread has be re-activated:
Here, a solution for heatmap tested in Matlab 2021b.
T = readtable('outages.csv');
h = heatmap(T,'Region','Cause');
% sloppy red line
annotation("line",[0.2 0.8],[0.2 0.8],"Color","red",'LineWidth',2)
% 2nd row horizontal line
plotLineThroughRowNr = 2;
nRow = numel(h.YData);
rowWidth = (h.InnerPosition(4))/(nRow);
lineYCoord = (nRow-plotLineThroughRowNr+0.5)*rowWidth + h.InnerPosition(2);
annotation("line",[h.InnerPosition(1) h.InnerPosition(1)+h.InnerPosition(3)],[lineYCoord lineYCoord],"Color","yellow",'LineWidth',2)
% 3rd column vertical line
plotLineThroughColumnNr = 3;
nColumn = numel(h.XData);
columnWidth = (h.InnerPosition(3))/(nColumn);
lineXCoord = (nColumn-plotLineThroughColumnNr+0.5)*columnWidth + h.InnerPosition(1);
annotation("line",[lineXCoord lineXCoord],[h.InnerPosition(2) h.InnerPosition(2)+h.InnerPosition(4)],"Color","magenta",'LineWidth',2)
Ahmed
Ahmed 2024 年 8 月 27 日

0 投票

Use MATLAB's imagesc instead of heatmap

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

タグ

質問済み:

2018 年 6 月 14 日

回答済み:

2024 年 8 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by