问题
I'm trying to plot several symbolic functions in the same subplot. Using ezsurf
makes it easy to plot symbolic functions, but it doesn't seem to be very configurable.
I can't colour the individual graphs (see the figure below). They all automatically take the normal jet
colourmap. How can they use different colormaps?

edit: Here's the new code I'm running using freezeColors
as suggested in the answer:
subplot(2,2,4)
for i = 1:numClasses
f(i) = M_k(i)/sum(M_k);
freezeColors
hold on
ezsurfc(x,y,f(i), [0 max(mean(1:numClasses))*2 0 max(mean(1:numClasses))*2],l)
switch i
case 1
colormap(copper)
case 2
colormap(bone)
case 3
colormap(spring)
case 4
colormap(hsv)
otherwise
colormap(jet)
end
hold off
unfreezeColors
alpha(0.7)
end
And this produces the image shown below:

Why are the colormaps still not different?
回答1:
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.
来源:https://stackoverflow.com/questions/22646622/using-multiple-colormaps-on-same-axis-with-ezsurf