24小时热门版块排行榜    

查看: 3844  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[公派出国] 售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急 +3 wsYGJnURYvm6 2026-08-31 3/150 2026-09-01 01:52 by o3EMxHUAQDtS
[考博] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +3 EZ67DG6CvcKL 2026-08-31 4/200 2026-09-01 01:30 by o3EMxHUAQDtS
[基金申请] 怎么看青基中了没有啊 +6 叶九微 2026-08-26 6/300 2026-08-31 23:54 by yudaoqian88
[考研] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +3 EZ67DG6CvcKL 2026-08-31 3/150 2026-08-31 22:12 by o3EMxHUAQDtS
[基金申请] 面上意见出来了 +12 黄鸟于飞Chao 2026-08-29 23/1150 2026-08-31 18:57 by 黄鸟于飞Chao
[基金申请] 29号明天会评吗 +4 笨笨唐 2026-08-28 4/200 2026-08-31 09:30 by huixian257
[基金申请] 基金不中,共勉 +12 eulota 2026-08-26 12/600 2026-08-31 08:42 by ZJTJZ
[基金申请] 有没有仍没收到信息的 +7 德尚中行 2026-08-27 8/400 2026-08-30 20:52 by purplejack
[基金申请] 2026年叶企孙基金 +4 bud_bud 2026-08-27 7/350 2026-08-29 07:23 by foolishmani
[基金申请] 为什么资助数各大高校都创新高,自己申请怎么就这么难 +12 Kittylucky 2026-08-27 13/650 2026-08-29 00:04 by superceng
[基金申请] 基金系统什么内容也没有 30+4 winsaint 2026-08-27 9/450 2026-08-28 11:06 by maolC
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 出来了 +9 trojank 2026-08-26 9/450 2026-08-26 14:25 by 宝贝虫子
[基金申请] 为什么国自然不能直接公布 +4 bjdxyxy 2026-08-26 4/200 2026-08-26 13:12 by qingmu1201
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[基金申请] 某些机构,以效率低为荣,以效率低作为存在感 +9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
信息提示
请填处理意见