使用ezsurf在同一轴上使用多个色彩映射

时间:2014-03-25 21:26:20

标签: matlab plot matlab-figure figure

我正在尝试在同一个子图中绘制几个符号函数。使用ezsurf可以很容易地绘制符号函数,但它似乎不是很容易配置。

我无法为各个图形着色(参见下图)。它们都会自动采用正常的jet颜色映射。他们如何使用不同的色彩图?

Multiple graphs, all using the same colour scheme

修改:以下是我使用freezeColors运行的新代码,如答案所示:

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

这会产生如下所示的图像:

Too much bone!

为什么色彩图仍然没有差异?

1 个答案:

答案 0 :(得分:4)

由于通过axes更改图中一个colormap的颜色贴图会更改图中所有axes的颜色贴图,因此您需要使用变通方法在您的图片中获取不同的颜色贴图个别子情节。 MathWorks文章"Using multiple colormaps in a single figure"列出了三种方法:

  1. Combine multiple colormaps into one,并为不同的轴使用连接地图的不同部分(这仅适用于图像)
  2. 如果您有图像处理工具箱(再次,仅适用于图像)
  3. ,请使用subimage
  4. freezeColors文件交换提交,可以保存任何图表色彩图。
  5. freezeColors的基本用法与hold类似。对于不同轴上的图:

    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)
    

    对于相同轴上的图:

    surf(peaks) % jet
    freezeColors
    hold on
    mesh(peaks')
    colormap(copper)
    

    输出:

    enter image description here

    注意:您必须在每个情节(freezeColorssurf等)后重复致电mesh

    注意2 :除非您想要恢复使用相同的颜色贴图,否则请勿使用unfreezeColors(例如在绘图循环中)。这修复了编辑中添加的第二个问题。

相关问题