Matlab:如何为同一图中的不同表面分配不同的颜色图/颜色条 [英] Matlab: How to assign different colormaps/colorbars to different surfaces in the same Figure

查看:246
本文介绍了Matlab:如何为同一图中的不同表面分配不同的颜色图/颜色条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Matlab 还很陌生,有几个问题.我在同一个图形中有两个曲面和一个平面.我想为 b 使用不同的颜色图和颜色条,为 c 使用另一个颜色图和颜色条.s 是固定颜色,所以没问题.

I am fairly new to Matlab and have a few questions. I got two surfaces and a plane in the same figure. I want to use different colormap and colorbar for b and another colormap and colorbar for c. s is fixed color so it's not a problem.

让我试着解释一下我想要达到的目标:

Let me try to explain what I am trying to achieve:

cmap1=colormap(topopathy) -->cmap1 是预期的 64x3 两倍

cmap1=colormap(topobathy) -->cmap1 is 64x3 double as expected

cmap2=colormap(redwhitegreen)

使用 cmap1 创建 cdata1(这是我无法弄清楚的第一部分,如何使用 cmap1 缩放 z 数据,默认情况下 CData 包含 z 值)

create cdata1 using cmap1 (this is the first part I cannot figure out, how to scale z data using cmap1, by default CData contains the z values)

b=surf(x,y,z,cdata1)

colorbar for b 使用 z 值

colorbar for b using z values

c=pcolor(x,y,(z-z0)) - 我想对这个使用 cmap2.

c=pcolor(x,y,(z-z0)) - I want to use cmap2 for this one.

colorbar for c 使用 (z-z0) 值

colorbar for c using (z-z0) values

这是我目前所拥有的以及我遇到的问题

Here is what I have so far and the problems I encounter

b=surf(x,y,z);
colormap(topobathy);
cbar1=colorbar;
set(get(cbar1,'ylabel'),'String', 'Elevation (m)', 'Rotation', 90)
hold on;
s=surf(x,y,z1,'FaceColor',[0.278 0.788 0.788])
hold on;
change=z-z0;     
c=pcolor(x,y,change)
set(c,'ZData',100 + 0*change); %plotting it above the other surfaces
colormap(redwhitegreen)`

此时colormap为b设置为redwhitegreen,b的colorbar我无法使用自己的气候等获得第二个颜色条.

at this point colormap is set to redwhitegreen for b, colorbar of b I can't get the second colorbar with its own clim etc.

我使用了此链接中解释的 freezeColors 和 cbfreeze:http://blogs.mathworks.com/pick/2009/07/24/using-multiple-colormaps-in-a-single-figure/

I used the freezeColors and cbfreeze explained in this link: http://blogs.mathworks.com/pick/2009/07/24/using-multiple-colormaps-in-a-single-figure/

但是一件事在搞乱另一件事的同时有效(可能都是我的错).我想学习如何在不使用外部 m 文件的情况下完全控制我的对象.

but one thing works while messing another thing (probably all my fault). I want to learn how to have complete control over my objects without using external m files anyway.

感谢任何帮助.

推荐答案

基本思想是连接颜色图,然后移动/缩放不同绘图句柄的颜色数据 (CData)与颜色图的所需部分对齐.因此,在不知道您的自定义函数或特定数据是什么的情况下,您可以执行类似 colormap(topopathy(64); redwhitegreen(64)) 之类的操作,然后缩放 CDatab 进入范围 [1,64] 和 cCData 进入范围 [65,128].

The basic idea is that you concatenate the colormaps, and then shift/scale the color data (CData) of the different plot handles to line up with the desired portions of the colormap. So, without knowing what your custom functions or specific data are, you could do something like colormap(topobathy(64); redwhitegreen(64)) and then scale the CData of b into the range [1,64] and the CData of c into the range [65,128].

MathWorks 网站上有一个 优秀 指南,解释了所有这些(甚至使用 surf()pcolor() 就像你的例子):

There is an excellent guide on the MathWorks website that explains all this (even uses surf() and pcolor() like your example):

http://www.mathworks.com/support/tech-notes/1200/1215.html#Example_1

对于颜色条,您可以以类似的方式伪造刻度和标签.这是为上述示例制作颜色条的粗略镜头:

For the colorbar, you can just fake out the ticks and labels in a similar manner. Here is rough shot at making a color bar for the above example:

h = colorbar;
ticks = [1 16:16:64 64:16:128];
ticks(5:6) = [62 66];
set(h, 'YTick', ticks);

labels = num2str(repmat(linspace(min(Z(:)), max(Z(:)), 5), 1, 2)', 2);
set(h, 'YTickLabel', labels)

这篇关于Matlab:如何为同一图中的不同表面分配不同的颜色图/颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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