MATLAB Answers


How to insert a line over a heatmap using code?

Asked by Samantha Clayton on 14 Jun 2018
Latest activity Commented on by Osama Talaat Ibrahim on 27 Dec 2018
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.


Sign in to comment.

1 Answer

Answer by Robert U
on 15 Jun 2018

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);
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,


New MATLAB also have heatmap().
Not working with Heatmap finction in MATLAB 2018b

Sign in to comment.