How do I plot two figures with the same color limits in MATLAB 7.0 (R14)?

28 ビュー (過去 30 日間)
I have multiple plots each with their own range of values. I would like to plot them with the same color limits with one unified colormap that covers the range of values across all plots.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
To create a unified colormap that covers the range of values across multiple plots, use the MIN and MAX commands to find the full range of values for all images. Then use the CAXIS command to set the color axis scaling to be the same for all plots.
The following code is an example of how to do this for two subplots of a figure:
% Create a common meshgrid for two plots having different z values
[x,y]=meshgrid(-1:0.05:1, -1:0.05:1);
% Two different z-data plots for the same x and y data points
z1=sin(x.^2+y.^2);
z2=cos(x+y);
% Minimum and maximum values of the two plots
% This is useful in setting the limits of the colorbar
bottom = min(min(min(z1)),min(min(z2)));
top = max(max(max(z1)),max(max(z2)));
% Plotting the first plot
subplot(1,2,1)
h1=surf(x,y,z1);
shading interp;
% This sets the limits of the colorbar to manual for the first plot
caxis manual
caxis([bottom top]);
% Plotting the second plot
subplot(1,2,2)
h2=surf(x,y,z2);
shading interp;
% This sets the limits of the colorbar to manual for the second plot
caxis manual
caxis([bottom top]);
colorbar;
  1 件のコメント
Madhav Rajan
Madhav Rajan 2016 年 2 月 2 日
編集済み: MathWorks Support Team 2022 年 2 月 22 日
You can click on the cursor icon in the plot which allows you to edit the plot. With this you can click on the color bar and move it.
Another option would be to call 'colorbar' with the location set to 'manual' as follows:
>> colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
You can refer the following link for more information:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColor and Styling についてさらに検索

製品


リリース

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by