Using multiple colormaps on same axis with ezsurf
Asked Answered
W

1

1

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?

Wilek answered 25/3, 2014 at 21:26 Comment(2)
How do you want them colored? You can just run colormap(...) after ezsurf to recolor the surface.Osteoblast
I can't do that easily – it ends up recoloring other subplots as well.Wilek
O
4

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.

Osteoblast answered 25/3, 2014 at 22:3 Comment(3)
I edited my above question to show you what happens when I use freezeColors – maybe I'm not using it properly?Wilek
@NickSweet Hard to say without your data, but perhaps put unfreezeColors and hold off after the loop.Osteoblast
Got it! I didn't use unfreezeColors and that made it work! Thanks!Wilek

© 2022 - 2024 — McMap. All rights reserved.