24小时热门版块排行榜    

查看: 3782  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 354求调剂 +4 Tyoumou 2026-03-18 7/350 2026-03-18 21:45 by Tyoumou
[考研] 267一志愿南京工业大学0817化工求调剂 +8 SUICHILD 2026-03-12 8/400 2026-03-18 20:55 by winsuccess
[考研] 085600材料与化工 +5 安全上岸! 2026-03-16 5/250 2026-03-18 15:33 by cmz0325
[考研] 工科材料085601 279求调剂 +6 困于星晨 2026-03-17 6/300 2026-03-18 10:21 by kkcoco25
[考研] 307求调剂 +3 冷笙123 2026-03-17 3/150 2026-03-18 09:55 by macy2011
[考研] 268求调剂 +7 好运连绵不绝 2026-03-12 8/400 2026-03-17 20:28 by xilongliang
[考研] 290求调剂 +3 p asserby. 2026-03-15 4/200 2026-03-17 16:35 by wangkm
[考研] 材料与化工专硕调剂 +5 heming3743 2026-03-16 5/250 2026-03-17 14:03 by 勇敢太监王公公
[考博] 26申博 +4 八旬速览 2026-03-16 4/200 2026-03-17 13:00 by 轻松不少随
[考研] 304求调剂 +5 素年祭语 2026-03-15 5/250 2026-03-16 17:00 by 我的船我的海
[考研] 一志愿211 0703方向310分求调剂 +3 努力奋斗112 2026-03-15 3/150 2026-03-16 16:44 by houyaoxu
[考研] 070300化学学硕求调剂 +6 太想进步了0608 2026-03-16 6/300 2026-03-16 16:13 by kykm678
[考研] 一志愿华中师范071000,325求调剂 +6 RuitingC 2026-03-12 6/300 2026-03-16 14:50 by 可淡不可忘
[考研] 070303 总分349求调剂 +3 LJY9966 2026-03-15 5/250 2026-03-16 14:24 by xwxstudy
[考研] 297一志愿上交085600求调剂 +5 指尖八千里 2026-03-14 5/250 2026-03-14 17:26 by a不易
[考研] 304求调剂 +6 Mochaaaa 2026-03-12 7/350 2026-03-13 22:18 by 星空星月
[考研] 材料与化工求调剂一志愿 985 总分 295 +8 dream…… 2026-03-12 8/400 2026-03-13 22:17 by 星空星月
[考研] 304求调剂 +7 7712b 2026-03-13 7/350 2026-03-13 21:42 by peike
[硕博家园] 085600 260分求调剂 +3 天空还下雨么 2026-03-13 5/250 2026-03-13 18:46 by 天空还下雨么
[考博] 福州大学杨黄浩课题组招收2026年专业学位博士研究生,2026.03.20截止 +3 Xiangyu_ou 2026-03-12 3/150 2026-03-13 09:36 by duanwu655
信息提示
请填处理意见