24小时热门版块排行榜    

查看: 3823  |  回复: 0

bucheron

金虫 (小有名气)

[交流] 怎样在同一个图中画两个等高线图?

目的: 存在两组等高线,两组等高线有交集。将两个等高线画在同一个图中,每组等高线使用不同的colormap, 两组等高线的交集应该是两组颜色的重叠。

实现方法一

使用contour,不用填充颜色的contourf,以便第二组等高线不会覆盖住第一组的交集部分。使用例如colormap([cool(64);gray(64)])命令,将colormap变成两种色彩集的合并。


例子1

clear all % clear all the data in the workspace
close all % close all the current figures
clc % clear the command window
%-----------------------------
% generate the data
[X,Y,Z1] = peaks(64); % X,Y,Z data of the first group
Z2=X.^2+Y.^2; % Z data of the second group
%%
% first method
% use two axes in the same figure
% set the figure's properties
h=figure
scrsz = get(0,'ScreenSize');
set(h,'Position',[scrsz(4).*(1/8) scrsz(4).*(1/20) scrsz(3)*3/5 scrsz(4).*(4/5)])
%--------------------------------------------------------------------------
% the first axes
hAxes(1)=axes('Unit','pixels','position',[100 100 400 400]);
%--------
% combine two colormap in the same one, here we use 'jet' and 'gray'
colormap([jet(64);gray(64)])
% the jet color will be used two index the first contour and the gray will
% be used for the second one.
%--------
[c1,h1] = contour(X(1,,Y(:,1),Z1); % plot the first contour
set(h1,'ShowText','on')
cmin1=min(Z1();
cmax1=max(Z1();
% use caxis to set the limit of the colorbar, the first one will occupy the
% low half one
caxis(hAxes(1),[cmin1,2*cmax1-cmin1])
% then define the axis
set(hAxes(1),'YColor','k','Box','on');
set(hAxes(1),'FontName','Helvetica','FontSize',20,'LineWidth',1)
xlabel(hAxes(1),'$ X $ [-]','Color','k','Interpreter','LaTex','FontSize',20);
ylabel(hAxes(1),'$ Y $ [-]','Color','k','Interpreter','LaTex','FontSize',20);
set(hAxes(1),'xlim',[min(X(1,), max(X(1,)],'YAxisLocation','left','Color','w');
set(hAxes(1),'ylim',[min(Y(:,1)), max(Y(:,1))]);
%--------------------------------------------------------------------------
% the second axes
hAxes(2)=axes('Unit','pixels','position',get(hAxes(1),'position'));
[c2,h2] = contour(X(1,,Y(:,1),Z2); % plot the second contour
cmin2=min(Z2();
cmax2=max(Z2();
% use caxis to set the limit of the colorbar, the second one will occupy the
% higher half one
caxis(hAxes(2),[2*cmin2-cmax2,cmax2])
set(hAxes(2),'visible', 'off') % the the visable of axes 2 off

实现方法二
原则上来说,在一个figure中只能使用一种colormap,所以如果不像第一种方法定义colorbar,两组等高线的色调是一样的。解决这个问题可以采用freezecolor方法,即第一个contour采用一中colormap,然后freeze, 对第二个contour采用另外一个colormap,也freeze。
具体可以参考
http://ycc.math.fju.edu.tw/research/biology/b2012fMRI/fMRICODE/simtb_v18/simtb_v18/display/freezeColors/demo/html/freezeColors_pub.html
回复此楼

» 猜你喜欢

Born to suffer !Born to burn!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

找到一些相关的精华帖子,希望有用哦~

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 bucheron 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 听说今天filecode变了 +16 布布和一二 2026-08-06 30/1500 2026-08-06 21:37 by 虫友是什么虫
[基金申请] filecode +10 等待解的谜 2026-08-06 14/700 2026-08-06 21:16 by zhanghaozhu
[基金申请] 固定端突然变了,今天 +3 archvillain 2026-08-06 7/350 2026-08-06 21:05 by archvillain
[基金申请] filecode +8 布布和一二 2026-08-06 11/550 2026-08-06 20:41 by tangpu318
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +5 Tide man 2026-08-06 6/300 2026-08-06 20:19 by 苏知砚
[基金申请] 基金中了 +4 laoda193707 2026-08-06 4/200 2026-08-06 18:56 by olivermiaoer
[有机交流] 一个有机合成实验室都需要哪些设备? 50+3 kf2781974 2026-07-31 12/600 2026-08-06 15:11 by eddyin
[基金申请] 求各位大神看下 100+6 hpkpkpkp 2026-08-05 33/1650 2026-08-06 14:49 by zhiyanjiang
[教师之家] 咨询面上基金 +4 李长云 2026-07-31 7/350 2026-08-06 11:20 by 李长云
[基金申请] 影响面上的因素 +8 布布和一二 2026-08-05 11/550 2026-08-06 10:41 by 宝贝虫子
[基金申请] 8月时间戳变的,举个手。玩一下,释放压力 +9 archvillain 2026-08-04 11/550 2026-08-05 20:06 by wlwhappy
[基金申请] 面上再次挂了,太难了,躺也躺不了,倦也卷不过,小学校之殇! +22 低垂的野花 2026-07-31 30/1500 2026-08-05 18:03 by 低垂的野花
[基金申请] 好消息?这个有何含义??? +8 Tide man 2026-08-05 10/500 2026-08-05 16:14 by xmuxiaoyu
[考博] 【2027博士申请】纳米药物递送方向 20+3 13586093586 2026-08-03 4/200 2026-08-05 09:59 by lfy8008
[基金申请] 有没有H口的?有收到消息的吗? +3 超级海虾 2026-08-04 3/150 2026-08-04 17:26 by 学教育滴
[论文投稿] 十年后又回来了,论文投稿求助 +3 哈哈114477 2026-08-01 3/150 2026-08-04 15:40 by tegsgjy20
[基金申请] 纯娱乐,不喜欢勿喷 +7 Tide man 2026-08-04 10/500 2026-08-04 15:10 by loufangrui
[基金申请] 面上提前没消息,有中的吗 +14 archvillain 2026-08-02 18/900 2026-08-04 14:42 by archvillain
[基金申请] 娱乐 +4 Tide man 2026-08-03 4/200 2026-08-04 11:51 by wgch518
[基金申请] 什么时候能放榜呀? +3 Jacob678 2026-08-03 3/150 2026-08-03 16:14 by gltch
信息提示
请填处理意见