MATLAB Answers

Overlay curves over heatmap

13 views (last 30 days)
Hello everyone,
I was wondering if it is possible to plot curves over heatmap. It goes something like this:
X = 20:20:1000;
Y = 100:-2:1;
Z = randi(100,50,50);
h = heatmap(X,Y,Z);
hold on
for ii=1:5
curve = ii+1000./X;
plot(X, curve)
hold off
I want the curves to be above the heatmap. For example, in the figures below,Capture.PNG
the right figure should be on top of the left figure.
Any ideas?
Thanks in advance!


Sign in to comment.

Accepted Answer

Akira Agata
Akira Agata on 26 Dec 2019
How about the following way?
  1. Plot the heatmap
  2. Add axes over the heatmap
  3. Plot lines on the axes
  4. Set the background color of the axes to 'none'
  5. Adjust the axes size to fit to the heatmap
The following is an example.
% Sample data
cdata = [45 60 32; 43 54 76; 32 94 68; 23 95 58];
ax = axes;
ax.Color = 'none';
% Maybe it needs some adjustment, like:
ax.Position(3) = 0.72;
ax.XTick = [];
ax.YTick = [];

  1 Comment

or ohev shalom
or ohev shalom on 26 Dec 2019
Excellent! Thanks!
Another option I've found is to use pcolor instead of heatmap, with the cost of losing the written values inside the map...

Sign in to comment.

More Answers (0)

Sign in to answer this question.




Translated by