Overlaying Heat Map

The following considerations are necesary to use the overlay function with a heat map graph:
  • the heat map must be on the first position of the cell of graphs to overlay
  • two heat maps cannot be overlayed
  • by default, the overlayed graphs will adapt their axes to the heat map canvas

Default overlay

Using a overlay with a heatmap will create the graph or group of graphs with the heatmap as background canvas.

% initializing options and values for heatmap

op1 = struct('show',false) hm = heatmap([5 6 7 8;1 2 3 4],op1)

% initializing options and values for scatter

op2 = struct('show',false,'markerSize',10,'markerStroke','#0d261a') s = scatter([1.5 3 1.7 4],op2)

% initializing options and values for plot

op3 = struct('show',false,'lineWidth',2) p = plot([0 2 5 6],[0 2 0 3.5],op3) overlay({hm,s,p})

% overlaying heatmap with 2d graph

Overlay with axes scaling

Default overlay

f = @(x) 100*(x(:,2) - x(:,1).^2).^2 + (x(:,1) - 1).^2  

% objective function

rng(0)

% for tractability

x0 = [-1.2,1]

% starting point

[xmin,fmin,info,tr] = fminsearch(f,x0)

% running minimization

os = struct('markerSize',3,'markerFill','#4da6ff','show',false)

% optimization graphs options

ohm = struct('gradientHM',true,'rangeMin',0.2,'rangeMax',99,'show',false)

% heatmap options

f = @(x,y) 100*(y - x.^2).^2 + (x - 1).^2 [x,y] = meshgrid(-2:0.02:2, -1:0.02:3) hm=heatmap(f(x,y),ohm)

% graph containing heat map

sc = scatter(tr.x(:,1),tr.x(:,2),os)

% graph containing optimization points

overlay({hm,sc})

% overlaying heatmap with optimization points

Defining the options xAxisMin, xAxisMax, yAxisMin and yAxisMax in the heat map options, the overlayed graph will take them as axes.

ohm = struct('gradientHM',true,'rangeMin',0.2,'rangeMax',99,'show',false,'xAxisMin',-2,'xAxisMax',2,'yAxisMin',-1,'yAxisMax',3) 

% defining axes in heatmap options

hm=heatmap(f(x,y),ohm)

% graph containing heat map

overlay({hm,sc})

% overlaying heatmap with optimization points

Related functions

heatmap | overlay