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
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 CenterFile Exchange 中查找有关 Color and Styling 的更多信息

产品


版本

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by