使用ezsurf在同一轴上使用多个颜色图 [英] Using multiple colormaps on same axis with ezsurf

查看:99
本文介绍了使用ezsurf在同一轴上使用多个颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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?

编辑:这是我在答案中建议的使用freezeColors运行的新代码:

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?

推荐答案

由于通过colormap更改了图中一个axes的颜色映射,因此更改了图中所有axes的颜色,因此您需要使用解决方法,以在您的各个子图中获得不同的颜色图. MathWorks文章使用一个图形中包含多个颜色图" 列出了三种方法:

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. subimage (同样,仅适用于图片)
  2. freezeColors 文件交换提交,可以保存任何图色图.
  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.

freezeColors的基本用法类似于hold.对于不同轴上的图:

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)

对于相同轴上的图:

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

输出:

注意:您必须在每次绘制(surfmesh等)后重复调用freezeColors.

NOTE: You have to call freezeColors repeatedly after each plot (surf, mesh, etc.).

注意2 :请勿使用unfreezeColors(例如在绘图循环中),除非您想还原为使用相同的颜色图.这样可以将在编辑中添加的第二个问题修复为该问题.

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.

这篇关于使用ezsurf在同一轴上使用多个颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆