How to plot 2D colormap or heatmap?

42 次查看(过去 30 天)
I have 2 matrices, x and y each containing 100-200 datapoints. I want to plot heatmap (or 2D colormap) to show density. For example, x= 1:100; for i=1:100 y=rand(0.01:1); end

采纳的回答

Image Analyst
Image Analyst 2017-6-28
Try scatteredInterpolant() to generate a 2-D image from randomly scattered points, then use imshow() to display it, and colormap() to apply a colormap, and colorbar() to show a bar alongside the image.
  1 个评论
Anjali Gerg
Anjali Gerg 2018-8-29
while applying imshow() function to the object generated after scatteredInterpolation, it says the input number must be a number or logical. Can you suggest how we can apply imshow() after using scatterInterpolation?

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-8-29
Here is a snippet from my program:
% Make the scattered interpolant.
F = scatteredInterpolant(xi, yi, dataValues)
% Get a grid of points at everypixel location in the RGB image.
[xGrid, yGrid] = meshgrid(1:columns, 1:rows);
xq = xGrid(:);
yq = yGrid(:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);
fittedImage = reshape(vq, rows, columns);
imshow(fittedImage, []);

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by