🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
colormap - View and set current colormap - MATLAB
A colormap is a matrix of values that define the colors for graphics objects such as surface, image, and patch objects. MATLAB® draws the objects by mapping data values to colors in the colormap.
Discussions

What's your favorite colormap?
I really wish there were some good built-in colormaps. I keep trying to explain to my colleagues that they need to pick their colors carefully, and then I have to climb an extra hill of explaining where to find them and how to import them into Matlab properly. It makes it look like I'm wasting people's time More on reddit.com
🌐 r/matlab
16
11
April 3, 2024
How can I make a "color map" plot in matlab? - Stack Overflow
How is the gnuplot function different from Matlab's mesh? With Mesh the color is proportional to the surface height. ... I don't want a surface; I just want a 2D map with colors. ... Save this answer. ... Show activity on this post. By default mesh will color surface values based on the (default) jet colormap ... More on stackoverflow.com
🌐 stackoverflow.com
Colormap setting the colors i want
Hello, So I discovered Colormap, and I want to draw a Color map of a matrix A I got that has ranges from 0 to 1. But I don't want to use the colours Matlab provides (jet for example), I want to c... More on mathworks.com
🌐 mathworks.com
3
1
June 29, 2018
You should never use the default colors in Matlab. This is why and what you can do about it.

Thank you. Jet must die.

For those who are interested in using cbrewer.m, here's what I've got in my startup.m:

set(0,'DefaultAxesColorOrder',cbrewer('qual','Set2',8))
set(0,'DefaultLineLineWidth',1.2)
set(0,'DefaultFigureColormap',cbrewer('seq','YlOrRd',64));       

Makes looking at plots in Matlab way more tolerable. Substitute YlOrRd with your favorite colorbrewer colormap.

More on reddit.com
🌐 r/matlab
32
97
August 6, 2013
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
gray - Gray colormap array - MATLAB
This MATLAB function returns the gray colormap as a three-column array with the same number of rows as the colormap for the current figure (gcf).
🌐
MathWorks
mathworks.com › mapping toolbox › map display › 3-d relief maps
demcmap - Colormaps appropriate to terrain elevation data - MATLAB
This MATLAB function sets the colormap and color axis limits based on the elevation data limits derived from input argument Z.
🌐
Reddit
reddit.com › r/matlab › what's your favorite colormap?
r/matlab on Reddit: What's your favorite colormap?
April 3, 2024 - I don't think I have a favorite specific map. I usually just roll with the default Parula. If I'm looking for something specific like a diverging map or a color map that's not in a specific order, I really like cbrewer. It's got a ton of colormaps and you can customize the maps quite a bit.
Find elsewhere
🌐
MathWorks
mathworks.com › videos › colormaps-97486.html
How to Use Colormaps in MATLAB - MATLAB
February 15, 2022 - Learn how to utilize colormaps in MATLAB® to more effectively visualize and convey 2D and 3D graphics objects.
🌐
MathWorks
mathworks.com › matlabcentral › fileexchange › 51986-perceptually-uniform-colormaps
Perceptually uniform colormaps - File Exchange - MATLAB Central
October 2, 2019 - Ander Biguri (2026). Perceptually uniform colormaps (https://www.mathworks.com/matlabcentral/fileexchange/51986-perceptually-uniform-colormaps), MATLAB Central File Exchange.
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
Change Color Scheme Using a Colormap - MATLAB & Simulink
MATLAB® uses a default color scheme when it displays visualizations such as surface plots. You can change the color scheme by specifying a colormap.
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
bone - Bone colormap array - MATLAB
This MATLAB function returns the bone colormap as a three-column array with the same number of rows as the colormap for the current figure (gcf).
Top answer
1 of 4
43

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');

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);    

... 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; 

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:

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;

2 of 4
19

gevang's answer is great. There's another way as well to do this directly by using pcolor. Code:

[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
figure;
subplot(1,3,1);
pcolor(X,Y,Z); 
subplot(1,3,2);
pcolor(X,Y,Z); shading flat;
subplot(1,3,3);
pcolor(X,Y,Z); shading interp;

Output:

Also, pcolor is flat too, as show here (pcolor is the 2d base; the 3d figure above it is generated using mesh):

🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
Control Colormap Limits - MATLAB & Simulink
For many types of visualizations you create, MATLAB® maps the full range of your data to the colormap by default. The smallest value in your data maps to the first row in the colormap, and the largest value maps to the last row in the colormap.
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
hot - Hot colormap array - MATLAB
This MATLAB function returns the hot colormap as a three-column array with the same number of rows as the colormap for the current figure (gcf).
🌐
Johns Hopkins University
math.jhu.edu › ~shiffman › 370 › help › techdoc › ref › colormap.html
colormap (MATLAB Function Reference)
The kth row of the colormap defines the k-th color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of red, green, and blue. colormap(map) sets the colormap to the matrix map. If any values in map are outside the interval [0 1], MATLAB returns the error: Colormap must have values in [0,1]
🌐
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
spring - Spring colormap array - MATLAB
This MATLAB function returns the spring colormap as a three-column array with the same number of rows as the colormap for the current figure (gcf).