Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a "color map" plot in matlab?

Tags:

plot

matlab

I have some data (a function of two parameters) stored in a matlab format, and I'd like to use matlab to plot it. Once I read the data in, I use mesh() to make a plot. My mesh() plot gives me the the value of the function as a color and a surface height, like this:

A color and a surface height as a function of two independent variables.

What matlab plotting function should I use to make a 2D mesh plot where the dependent variable is represented as only a color? I'm looking for something like pm3d map in gnuplot.

like image 632
Dan Avatar asked Apr 02 '13 01:04

Dan


People also ask

How do I create a color map in MATLAB?

To create a custom colormap, specify map as a three-column matrix of RGB triplets where each row defines one color. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color.

How do you color a mesh in MATLAB?

The mesh plot uses Z for height and C for color. Specify the colors using a colormap, which uses single numbers to stand for colors on a spectrum. When you use a colormap, C is the same size as Z . Add a color bar to the graph to show how the data values in C correspond to the colors in the colormap.


1 Answers

By default mesh will color surface values based on the (default) jet colormap (i.e. hot is higher). You can additionally use surf for filled surface patches and set the 'EdgeColor' property to 'None' (so the patch edges are non-visible).

[X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R;  % surface in 3D figure; surf(Z,'EdgeColor','None'); 

enter image description here

2D map: You can get a 2D map by switching the view property of the figure

% 2D map using view figure; surf(Z,'EdgeColor','None'); view(2);     

enter image description here

... or treating the values in Z as a matrix, viewing it as a scaled image using imagesc and selecting an appropriate colormap.

% using imagesc to view just Z figure; imagesc(Z);  colormap jet;  

enter image description here

The color pallet of the map is controlled by colormap(map), where map can be custom or any of the built-in colormaps provided by MATLAB:

enter image description here

Update/Refining the map: Several design options on the map (resolution, smoothing, axis etc.) can be controlled by the regular MATLAB options. As @Floris points out, here is a smoothed, equal-axis, no-axis labels maps, adapted to this example:

figure; surf(X, Y, Z,'EdgeColor', 'None', 'facecolor', 'interp'); view(2); axis equal;  axis off; 

enter image description here

like image 145
gevang Avatar answered Sep 16 '22 19:09

gevang