How do I use multiple colormaps in a single figure in R2014b and later?

6 次查看(过去 30 天)
I have a figure in which I wish to use multiple colormaps. I would also like to know where the colormaps are stored and what are some of its properties. Examples will be useful.

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2021-3-3
What is a Colormap?
Colormaps are associated with axes and figures. A colormap is matrix of values between 0 and 1 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. For more information about how data relates to a colormap, see the topics here:
Colormaps can be any length, but must be three columns wide. Each row in the matrix defines one color using an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]. A value of 0 indicates no color and a value of 1 indicates full intensity. For example, this is a  colormap with five colors: black, red, green, blue, and white.
cmap = [0 0 0
1 0 0
0 1 0
0 0 1
1 1 1];
View Colormap
Use the colormap function to view the colormap for a particular axes or figure. For example, this code returns the colormap for the current axes. 
cmap = colormap(gca)
Change Colormap
Use the colormap function to change the colormap for a particular axes or figure. You can specify the colormap on the figure level (affects all axes in the figure) or on the axes level. For example, this code changes the colormap for all axes in the current figure.
colormap(gcf,summer)
You can assign a different colormap to each axes by passing the Axes object as the first input argument to the colormap function. For example, this code uses a different colormap for each subplot.
ax1 = subplot(1,2,1);
surf(peaks(25))
cmap1 = jet(5);
colormap(ax1,cmap1)
ax2 = subplot(1,2,2);
surf(peaks(25))
cmap2 = summer(5);
colormap(ax2,cmap2)
While one axes cannot have two colormaps, you can create an image using two overlapping axes objects to obtain what looks like a plot with multiple colormaps. Please see the following MATLAB Answers post for more details.https://www.mathworks.com/matlabcentral/answers/194554-how-can-i-use-and-display-two-different-colormaps-on-the-same-figure

更多回答(0 个)

类别

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

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by