1
votes

This questions is vaguely answered elsewhere. Therefore, please answer it before down voting and marking it as duplicate. I have searched Stackoverflow and MATLAB forum

I am trying to plot the spatial plot of India (see below), with multiple subplots. Here I want to use one representative color bar as shown in the figure.

The color bar which I am getting is for the last subplots, and it's values does not corresponds with other subplots.

Below is, how I am trying to add the color bar and respective output

ax(1)=subplot(2,3,1)

worldmap('India');
shape=shaperead('India.shp',  'UseGeoCoords', true);
geoshow(shape, 'FaceColor', 'w')
hold on
geoshow(lat,lon,data_fill, 'DisplayType', 'surface');
colormap('hsv');

.
.
.

ax(6)=subplot(2,3,6)

worldmap('India');
shape=shaperead('India.shp',  'UseGeoCoords', true);
geoshow(shape, 'FaceColor', 'w')
hold on
geoshow(lat,lon,data_fill, 'DisplayType', 'surface');
colormap('hsv');


h=colorbar;

cmin = min(data_fill_of_all_sub_plot);
cmax = max(data_fill_of_all_sub_plot);

if mod(cmax,5)==0
    cmax=cmax+5;
else
    cmax=cmax+(5-mod(cmax,5));
end
caxis([cmin cmax])  % to fix the colormap scale

set(h, 'Position', [.95 .42 .01 .5])

Output

image

How to put a single color bar for all the subplots?

1
I don't understand: you want a single colorbar for all subplots and showing your code outputing exactly that. what is the question? - Ander Biguri
I am getting single colorbar for all subplots but the colorbar values do not correspond with other subplots. It is like I am putting colorbar for last subplot only. Here I have `caxis([cmin cmax])' used in ax(6)=subplot(2,3,3) only, I guess now, need to include it in ax(1), ax(2), ax(3), ax(4) and ax(5) as well. Am I right? - dSb
I have no idea what you are saying. Why dont you use caxis in the others also then? - Ander Biguri
yes, it works when I add caxis in others as well. - dSb
then, if it works, what is your question? - Ander Biguri

1 Answers

0
votes

I figured out the mistake

caxis([cmin cmax])

is required to be included in every subplot section.

In present code it is only included after ax(6)=subplot(2,3,6)