How do I create a colorbar for my subplots and associate the colorbar with the figure rather than each individual axes in MATLAB 7.7 (R2008b)?
조회 수: 6 (최근 30일)
이전 댓글 표시
I am trying to get a colorbar to reside to the right-hand-side of a series of four subplots. If I issue the command COLORBAR it squishes a colorbar to the right-hand-side of the bottom subplot. The desired result is to have the colorbar stretch from the top to the bottom of the page, spanning all four subplots.
Here is my attempt:
subplot(4,1,1);
imagesc(magic(5));
subplot(4,1,2);
imagesc(magic(6));
subplot(4,1,3);
imagesc(magic(7));
subplot(4,1,4);
imagesc(magic(8));
colorbar
채택된 답변
MathWorks Support Team
2011년 2월 11일
Below is an example that demonstrates how to create a colorbar for your subplots, and associate the colorbar with the figure rather than each individual axes. Note that the position of each of the axes needs to be altered.
ax(1)=subplot(4,1,1);
imagesc(magic(5),[1 64])
ax(2)=subplot(4,1,2);
imagesc(magic(6),[1 64])
ax(3)=subplot(4,1,3);
imagesc(magic(7),[1 64])
ax(4)=subplot(4,1,4);
imagesc(magic(8),[1 64])
h=colorbar;
set(h, 'Position', [.8314 .11 .0581 .8150])
for i=1:4
pos=get(ax(i), 'Position');
set(ax(i), 'Position', [pos(1) pos(2) 0.85*pos(3) pos(4)]);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!