Question

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?

Multiple graphs, all using the same colour scheme

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:

Too much bone!

Why are the colormaps still not different?

Was it helpful?

Solution

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:

  1. Combine multiple colormaps into one, and use different portions of the concatenated map for different axes (this only works for images)
  2. Use subimage if you have the Image Processing Toolbox (again, only for images)
  3. 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:

enter image description here

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top