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 Walter Roberson
on 15 Jun 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,


  1 Comment

New MATLAB also have heatmap().

Sign in to comment.