How can I have a standard colorbar for different plots in MATLAB 7.0.4 (R14SP2)?

조회 수: 3 (최근 30일)
I am trying to compare different sets of data, with different sets of ranges using PCOLOR.
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?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
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)
Afte you run the above code, you will observe that both plots share the same colorbar.
  댓글 수: 1
Jing Ci Neo
Jing Ci Neo 2018년 7월 30일
편집: Jing Ci Neo 2018년 7월 30일
Is the answer the same if I am using imagesc and multiple plots using subplot?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by