Since changing the color map of one axes
in a figure via colormap
changes it for all axes
in the figure, you need to use a workaround to get different color maps in your individual subplots. The MathWorks article "Using multiple colormaps in a single figure" lists three methods:
- Combine multiple colormaps into one, and use different portions of the concatenated map for different axes (this only works for images)
- Use
subimage
if you have the Image Processing Toolbox (again, only for images) - The
freezeColors
File Exchange submission, which can hold any plots colormap.
The basic usage of freezeColors
is similar to hold
. For plots on different axes:
subplot(1,2,1)
ezsurf('sqrt(x^2 + y^2)')
colormap(jet)
freezeColors % submission by John Iversen
subplot(1,2,2)
contour(peaks,30)
colormap(copper)
For plots on the same axes:
surf(peaks) % jet
freezeColors
hold on
mesh(peaks')
colormap(copper)
Output:
NOTE: You have to call freezeColors
repeatedly after each plot (surf
, mesh
, etc.).
NOTE 2: Do not use unfreezeColors
(e.g. in a plotting loop) unless you want to revert to using the same color maps. This fixed the second question added in the edit to the question.