Reference:http://www.mathworks.com/matlabcentral/answers/100950-how-can-i-have-a-standard-colorbar-for-different-plots-in-matlab-7-0-4-r14sp2

Question:

I am trying to compare different sets of data, with different sets of ranges using PCOLOR.

% Plot # 1
figure(1);
C = rand(5); % Random values between 0 and 1 for Plot#1
p = pcolor(C);
colorbar; % colorbar is set for figure(1) % Clears the workspace
clear all;
clc;
% Plot # 2
figure(2);
C = .25*rand(5) + .5; % Create random values between .375 and .625 for Plot # 2
p = pcolor(C);
colorbar; % colorbar is set for figure(2)

   

The COLORBAR function generates a different colorbar for each set of data. Thus, it becomes difficult for me to compare the different data sets, as the ranges and tick labes on the colorbars are different for each data set. So, how can I have a standard colorbar for different plots?

Answer:

One soultion is to use set(gca, 'CLim', [cMin cMax])  funciton

In order to have a standard colorbar for plots generated using PCOLOR you first need to set the same ‘CLim’ property for the axes of each plot before you enable the colorbar for that plot (i.e. by executing the COLORBAR command).

Since the colorbar chooses limits and labels according to the ‘CLim’ property of the associated axes, it is important to create (or recreate) the colorbar after setting the ‘CLim’ property.

For example:

% Plot # 1
figure(1);
a = axes;
C = rand(5); % Random values between 0 and 1 for Plot#1
p = pcolor(C);
set(a, 'CLim', [0 1]); % CLim property is set for figure(1) before colobar
colorbar; % colorbar is set for figure(1)
% Clears the workspace
clear all;
clc;
% Plot # 2
figure(2);
a = axes;
C = .25*rand(5) + .5; % Create random values between .375 and .625 for Plot # 2
p = pcolor(C);
set(a, 'CLim', [0 1]); % CLim property is set for figure(2) before colobar
colorbar; % colorbar is set for figure(2)

Another solution is to use caxis([cmin cmax]) function

figure(1);
C = rand(5); % Random values between 0 and 1 for Plot#1
p = pcolor(C);
caxis([0,1]);
colorbar figure(2);
C = .25*rand(5) + .5; % Create random values between .375 and .625 for Plot # 2
p = pcolor(C);
caxis([0,1]);
colorbar

  Afte you run the above code, you will observe that both plots share the same colorbar. Results are as follows:

统一Matlab下不同子图的色标colorbar的更多相关文章

  1. matlab下K-means Cluster 算法实现

    一.概念介绍 K-means算法是硬聚类算法,是典型的局域原型的目标函数聚类方法的代表,它是数据点到原型的某种距离作为优化的目标函数,利用函数求极值的方法得到迭代运算的调整规则.K-means算法以欧 ...

  2. 【转】 MATLAB下如何指定GPU资源

    [转] MATLAB下如何指定GPU资源 原文链接

  3. Matlab下的文件执行路径

    Matlab下有时命令出错,源于Command窗口的路径不正确.快捷键的执行会受此影响.

  4. Matlab下imwrite,Uint16的深度图像

    Matlab下imwrite,Uint16的深度图像 1. 在Matlab命令窗口输入命令: help imwrite 会有如下解释: If the input array is of class u ...

  5. 关于libsvm工具箱在64位matlab下的安装说明

    LIBSVM工具箱的安装 基本方法: 1.在网上下载LIBSVM工具箱. http://www.csie.ntu.edu.tw/~cjlin/libsvm/ 2.将LIBSVM工具箱所在目录添加到MA ...

  6. MATLAB下跑Faster-RCNN+ZF实验时如何编译自己需要的external文件

    本篇文章主讲这篇博客中的(http://blog.csdn.net/sinat_30071459/article/details/50546891)的这个部分,如图所示 注:截图来自 小咸鱼_ 的博客 ...

  7. libSVM在matlab下的使用安装

    1) 从LIBSVM的官网http://www.csie.ntu.edu.tw/~cjlin/libsvm/上下载最新版本的LIBSVM,当前版本为libsvm-3.18.zip 2) 解压压缩包到电 ...

  8. matlab下使用svmlib工具包

    虽然网络上已经有了很多的类似的东西了吧.但是呢,我自己还是要写一写的. 安装: 对于 libsvm工具包,我们可以去官方网站下载,网址为:http://www.csie.ntu.edu.tw/~cjl ...

  9. matlab下的caffe接口配置(Windows)

    本文基于大部分网上方法 http://blog.csdn.net/d5224/article/details/51916178,外加一点自己的个人实际配置经历,环境变量在配置后尽管显示正确并且重启多次 ...

随机推荐

  1. CodeForces 18C

    Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...

  2. Cocos2dx隐藏iOS7状态栏】通过添加Plist Key隐藏iOS7状态栏

    本站文章均为李华明Himi原创,转载务必在明显处注明:(作者新浪微博:@李华明Himi)  转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/%e9%9a% ...

  3. 1874 素数和最大 - Wikioi

    题目描述 Description 有一天萌萌哒Sevenkplus在跟素数们玩>_<...他玩着玩着突然想到一个问题!就是这样的:    从1到n这n个自然数中,选出一些数使得它们之间两两 ...

  4. BZOJ 4127 Abs 解题报告

    这个题感觉很厉害的样子.. 首先我们注意到一点:每次加的 $d$ 都是非负的. 那么就说明一个数只可能从负数变成非负数并且只会变一次. 所以我们就可以暴力地去改变一个数的正负情况. 然后我们就可以用树 ...

  5. [转载]AOP面向方面编程

    1.引言 软件开发的目标是要对世界的部分元素或者信息流建立模型,实现软件系统的工程需要将系统分解成可以创建和管理的模块.于是出现了以系统模块化特性的面向对象程序设计技术.模块化的面向对象编程极度极地提 ...

  6. python time相关操作

    1.获取当前时间的两种方法: 代码如下: import datetime,timenow = time.strftime("%Y-%m-%d %H:%M:%S")print now ...

  7. hdu 4672 Present Day, Present Time 博弈论

    看了解题报告才知道怎么做!! 题意:有 N 堆石子和 M 个石子回收站,每回合操作的人可以选择一堆石子,从中拿出一些 放到石子回收站里(可以放进多个回收站,每个回收站可以使用无数次),但每个石子回收站 ...

  8. poj The Clocks 高斯消元

    由于数据量不大,所以这题有很多解法. 我用的是高斯消元化为逆矩阵解决的…… 代码如下: #include<stdio.h> #include<iostream> using n ...

  9. 使用头文件cfloat中的符号常量获知浮点类型数据的表数范围---gyy整理

    使用头文件cfloat中的符号常量获知浮点类型数据的表数范围 cfloat头文件包含了系统的浮点数的长度限制 头文件climits中的符号常量是获知整型数据的表数范围,并不能获取浮点类型数据的表数范围 ...

  10. CentOS下安装XAMPP详细教程

    现在php的集成运行环境越来越多,个人比较喜欢XAMPP,更新速度快,好用,安装便捷.windows下面的安装,就是下一步.下一步,没什么好说的,详细说一下linux下面的安装,这里以CentOS为例 ...