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

查看:799
本文介绍了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(topobathy)-> cmap1是预期的64x3倍

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

cmap2 = colormap(红色白色绿色)

使用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)

颜色条,用于使用z值的b

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.

颜色条,用于使用(z-z0)值的c

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)`

此时,b的颜色图设置为redwhitegreen,b的颜色栏设置为 我无法获得带有其自身的clim等色标的第二个颜色条.

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(topobathy(64); redwhitegreen(64))的操作,然后将bCData缩放到[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网站上有一个 excellent 指南,可以解释所有这些内容(甚至像您的示例一样使用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天全站免登陆