博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
统一Matlab下不同子图的色标colorbar
阅读量:6088 次
发布时间:2019-06-20

本文共 2439 字,大约阅读时间需要 8 分钟。

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 # 1figure(1);C = rand(5);            % Random values between 0 and 1 for Plot#1p = pcolor(C);         colorbar;                 % colorbar is set for figure(1)% Clears the workspaceclear all;clc;% Plot # 2figure(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 # 1figure(1);a = axes;C = rand(5);            % Random values between 0 and 1 for Plot#1p = pcolor(C);         set(a, 'CLim', [0 1]); % CLim property is set for figure(1) before colobarcolorbar;                 % colorbar is set for figure(1)% Clears the workspaceclear all;clc;% Plot # 2figure(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#1p = 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:

转载于:https://www.cnblogs.com/cumtb3S/p/3905546.html

你可能感兴趣的文章
gitlab 2.6.x升级到2.7.0
查看>>
1.1编程基础之输入输出_01:Hello, World!
查看>>
linux的functions之killproc函数详解
查看>>
samba案例配置及自动挂载
查看>>
nagios主配置文件nagios.cfg详解
查看>>
细说多线程(七) —— 并行编程与PLINQ
查看>>
Unit 06 实际接触工作
查看>>
python执行系统命令的方法
查看>>
Docker基础概念与框架
查看>>
linux基础之帮助文档---常用的命令
查看>>
算法学习之路|POJ2689(素数筛)
查看>>
linux内核监控与配置
查看>>
loadrunner安装运行一步一步来(多图)
查看>>
注册类型转换器
查看>>
自定义的泛型类和泛型约束
查看>>
Cacti进阶应用篇
查看>>
cacti的简单讲解1
查看>>
LVS基本概念杂记
查看>>
自动化运维工具ansible源码安装方法
查看>>
String
查看>>