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

23 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
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 Kommentar
Madhav Rajan
Madhav Rajan am 2 Feb. 2016
Bearbeitet: MathWorks Support Team am 22 Feb. 2022
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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Produkte


Version

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by