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

29 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Giu 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 Commento
Madhav Rajan
Madhav Rajan il 2 Feb 2016
Modificato: MathWorks Support Team il 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:

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Color and Styling in Help Center e File Exchange

Prodotti


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by