Question related to pcolor bar and its position

조회 수: 6 (최근 30일)
Ashfaq Ahmed
Ashfaq Ahmed 2023년 2월 23일
댓글: Les Beckham 2023년 2월 23일
Hi! Can anyone please tell me
a) how can I use one long pcolorbar at the right side of this figure instead of using 4 different colorbar for four subplots?
This is the figure -
b) How to minimize the distances between teh four subplots, so that they are put closer to each other?
The code I am using for the plot is this -
for ii = 1:4
ax(ii) = subplot(2,2,ii);
h{ii} = pcolor(LON,LAT,flip(Tide_type{ii}));
set(h{ii}, 'EdgeColor', 'none');
shading interp;
colorbar;
caxis([12.5 15.5]);
setup_plots(ax(ii))
end
Any feedback will be much appreaciated, thank you!!
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 2월 23일
tiledlayout can supposedly get tiles closer together than subplot does.

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

채택된 답변

Jacob Ward
Jacob Ward 2023년 2월 23일
You can manually change the position of the colorbar using the 'position' property. Here's an example:
fig = figure;
subplot(2,2,1)
imagesc([0 1 0; 1 2 1; 0 1 0;])
subplot(2,2,2)
imagesc([0 1 0; 1 2 1; 0 1 0;])
subplot(2,2,3)
imagesc([0 1 0; 1 2 1; 0 1 0;])
subplot(2,2,4)
imagesc([0 1 0; 1 2 1; 0 1 0;])
pos = get(subplot(2,2,4),'Position');
colorbar('Position', [pos(1)+pos(3)+0.01 pos(2) 0.03 pos(2)+pos(4)*2.07])
  댓글 수: 1
Les Beckham
Les Beckham 2023년 2월 23일
Note that this is a little bit easier using tiledlayout instead of subplot, plus it is easier to control the spacing between and around the tiles. Details on the spacing options are here
figure
tl = tiledlayout(2,2, 'TileSpacing', 'compact', 'Padding', 'compact');
nexttile
imagesc([0 1 0; 1 2 1; 0 1 0;])
nexttile
imagesc([0 1 0; 1 2 1; 0 1 0;])
nexttile
imagesc([0 1 0; 1 2 1; 0 1 0;])
nexttile
imagesc([0 1 0; 1 2 1; 0 1 0;])
cbh = colorbar;
cbh.Layout.Tile = 'east';

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by