필터 지우기
필터 지우기

How to place a common colorbar for tiledlayout plots?

조회 수: 62 (최근 30일)
Abhishek Chakraborty
Abhishek Chakraborty 2022년 4월 24일
댓글: Abhishek Chakraborty 2022년 4월 24일
I wanted to place a large common colorbar towards "east" for a series of plots using tiledlayout. I used the following code:
figure;
t = tiledlayout(2,2,'TileSpacing','none','Padding','none');
nexttile;
imagescn(x,y,A);
cb = colorbar;
hold on;
stipple(x',y',A1);
mymap.EdgeAlpha=0; %Removes the grids
colorbar;
box on;
set(gca,'linew',2); % thickens the axis
axis equal; %important for maps so that there is no stretch
set(gca,'XMinorTick','on','YMinorTick','on');
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
% To set label to colorbar
h = colorbar;
%Axis ticks bolded
set(gca,'TickLabelInterpreter','none');
set(gca,'fontweight','bold','fontsize',12);
title('A','FontWeight','bold','FontSize',14,'FontName','Helvetica'); % title bold and size 14
cb = colorbar;
cmocean('balance','pivot') % sets the colormap with zero in the middle
set(gca,'xticklabel',{[]});set(gca,'yticklabel',{[]});
hold on;
geoshow(shapefile, 'FaceColor', 'none','LineWidth',1); %No facecolor
set(cb,'FontSize',10)
nexttile;
imagescn(x,y,B);
cb = colorbar;
hold on;
stipple(x',y',B1);
mymap.EdgeAlpha=0; %Removes the grids
colorbar;
box on;
set(gca,'linew',2); % thickens the axis
axis equal; %important for maps so that there is no stretch
set(gca,'XMinorTick','on','YMinorTick','on');
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
% To set label to colorbar
h = colorbar;
%Axis ticks bolded
set(gca,'TickLabelInterpreter','none');
set(gca,'fontweight','bold','fontsize',12);
title('B','FontWeight','bold','FontSize',14,'FontName','Helvetica'); % title bold and size 14
cb = colorbar;
cmocean('balance','pivot') % sets the colormap with zero in the middle
set(gca,'xticklabel',{[]})
set(gca,'yticklabel',{[]})
hold on;
geoshow(shapefile, 'FaceColor', 'none','LineWidth',1); %No facecolor
set(cb,'FontSize',10)
nexttile;
imagescn(x,y,C);
cb = colorbar;
hold on;
stipple(x',y',C1);
mymap.EdgeAlpha=0; %Removes the grids
colorbar;
box on;
set(gca,'linew',2); % thickens the axis
axis equal; %important for maps so that there is no stretch
set(gca,'XMinorTick','on','YMinorTick','on');
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
% To set label to colorbar
h = colorbar;
%Axis ticks bolded
set(gca,'TickLabelInterpreter','none');
set(gca,'fontweight','bold','fontsize',12);
title('C','FontWeight','bold','FontSize',14,'FontName','Helvetica'); % title bold and size 14
cb = colorbar;
cmocean('balance','pivot') % sets the colormap with zero in the middle
set(gca,'xticklabel',{[]})
set(gca,'yticklabel',{[]})
hold on;
geoshow(shapefile, 'FaceColor', 'none','LineWidth',1); %No facecolor
set(cb,'FontSize',10)
nexttile;
imagescn(x,y,D);
cb = colorbar;
hold on;
stipple(x',y',D1);
mymap.EdgeAlpha=0; %Removes the grids
colorbar;
box on;
set(gca,'linew',2); % thickens the axis
axis equal; %important for maps so that there is no stretch
set(gca,'XMinorTick','on','YMinorTick','on');
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
% To set label to colorbar
h = colorbar;
%Axis ticks bolded
set(gca,'TickLabelInterpreter','none');
set(gca,'fontweight','bold','fontsize',12);
title('D','FontWeight','bold','FontSize',14,'FontName','Helvetica'); % title bold and size 14
cb = colorbar;
cmocean('balance','pivot') % sets the colormap with zero in the middle
set(gca,'xticklabel',{[]});set(gca,'yticklabel',{[]});
This code is giving individual colorbars for each plot. But I want a common colorbar for all the plots together towards the eastern end. How to do it?

채택된 답변

Matt J
Matt J 2022년 4월 24일
tiledlayout(2,2)
nexttile; nexttile; nexttile; nexttile
cb = colorbar;
cb.Layout.Tile = 'east';
  댓글 수: 8
Matt J
Matt J 2022년 4월 24일
편집: Matt J 2022년 4월 24일
You must apply cmocean in all the nexttile blocks. Currently you are only doing so in the last block.
Abhishek Chakraborty
Abhishek Chakraborty 2022년 4월 24일
It worked. Thanks a lot .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by