필터 지우기
필터 지우기

Aligning subplots (colorbar and axis equal issue)

조회 수: 23 (최근 30일)
TP
TP 2018년 8월 17일
편집: jonas 2018년 8월 17일
What would be the simplest way to align the x-axes of the two subplots while keeping the "axis equal" and "axis tight" properties on the bottom subplot? Thank you.
figure('position',[680 183 560 795]) subplot(2,1,1) imagesc(rand(1,3)) colorbar
subplot(2,1,2) imagesc(rand(3,3)) axis equal axis tight

답변 (1개)

jonas
jonas 2018년 8월 17일
편집: jonas 2018년 8월 17일
This was more difficult than I'd imagined, as axis equal changes the 'tightinset' and 'aspectratio' of the plot. This fileexchange function ( link ) proved very helpful. Using this function, you can try this code:
%%Original code
figure('position',[680 183 560 795])
h(1)=subplot(2,1,1)
imagesc(rand(1,3))
colorbar
h(2)=subplot(2,1,2)
imagesc(rand(3,3))
axis equal
axis tight
%%Add this section
pos{1} = plotboxpos(h(1))
pos{2} = plotboxpos(h(2))
NewPos=[pos{2}(1) pos{1}(2) pos{2}(3) pos{1}(4)]
set(h(1),'position',NewPos);
See attachment for results. The x-axes are aligned while the original height is maintained.

카테고리

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

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by