MATLAB Answers

Use image function to create heat map and 3D plot?

165 views (last 30 days)
Andrew Poissant
Andrew Poissant on 25 Jan 2018
Answered: Arun Mathamkode on 1 Feb 2018
I have 4 variables (X, Y, Z, W) I am trying to plot at the same time. I already have code set up to plot a heat map showing population count over a range of X and Y values. These population values are found in variable Z. However, now I am trying to make a 3D heat map using the image function to add in height values, found in variable W. How would I go about doing this? I want the heat map and colorbar to show the range of values for population count, not height. The z axis can just show the height values. I am able to use surfc to plot X,Y,W as seen below too, but I don't know how to combine the two plots. The four variables are attached as .mat files.
traj_xmin = 0; % traj plot axis limits
traj_xmax = 3200;
traj_ymin = 0;
traj_ymax = 1400;
figure(1)
im = image('XData', [traj_xmin traj_xmax], 'YData', [traj_ymin traj_ymax], 'CData', Z, 'CDataMapping', 'scaled');
colormap(flipud(pink));
colorbar
AxesH = gca;
axis(AxesH, 'tight');
figure(2)
rotate3d
surfc(X,Y,W);
colorbar
AxesH = gca;
axis(AxesH, 'tight');
zlim([0 200]);

  0 Comments

Sign in to comment.

Answers (1)

Arun Mathamkode
Arun Mathamkode on 1 Feb 2018
You can use the cdata property in the surface properties to assign vertex colors on a surface.
figure,surf(X,Y,Z,'cdata',W);

  0 Comments

Sign in to comment.

Categories