필터 지우기
필터 지우기

Moving the cross point of vertical and horizontal axes to (0,0)

조회 수: 4 (최근 30일)
Kourosh
Kourosh 2016년 7월 2일
댓글: dpb 2016년 7월 17일
Hello,
Does any body know that in plotting figures, how I can move the cross point of vertical and horizontal axes to (0,0)? I have figures and the horizontal and vertical axes always cross in the lowest left of the figures. How to move this point to (0,0)?
Regards,
Kourosh

답변 (2개)

dpb
dpb 2016년 7월 2일
If have recent version there's now a 'center' value on the position properties. If using earlier release, just answered a short time ago-- <how-to-shift-xaxis-location-to-origin-0>
It only does the one axis, but the pattern to follow for the other should be obvious...
  댓글 수: 3
Kourosh
Kourosh 2016년 7월 17일
편집: dpb 2016년 7월 17일
Hi dpb,
Thanks for the answer. My Matlab is R2011b so I think I should shift the axes through your code. I tried it for both axes but there is something wrong. Could you check where I make a mistake? Many thanks.
hAx=axes; % a new axes
plot (X,Y) % plot the data...
yl=ylim; % get y-axis limits
xl=xlim % get x-axis limits
pos=get(hAx,'position'); % and axes position vector
yrat=yl(end)/(yl(end)-yl(1)); % fractional position of origin relative y range
yht=yrat*pos(4); % adjusted second axes height
pos(2)=pos(2)+pos(4)-yht; % new bottom is top position {pos(2)+pos(4)} less height
pos(4)=yht; % and new height into vector
xrat=xl(end)/(xl(end)-xl(1)) % fractional position of origin relative x range
xht=xrat*pos(3) % adjusted second axes height
pos(1)=pos(1)+pos(3)-xht % new left is right position {pos(1)+pos(3)} less width
pos(3)=xht % and new width into vector
hAx(2)=axes('position',pos,'color','none'); % second axes with this position an no color
hAx(1)=axes('position',pos,'color','none') % first axes with this position an no color
set(hAx(2),'ytick',[]) % clear unwanted ticks from showing...
set(hAx(1),'xticklabel',[]) % clear labels on first x-axis
linkaxes(hAx,'x') % and synchronize x-axes
dpb
dpb 2016년 7월 17일
If you move both x- and y-, I'd overlooked you'll need four axes, not just two to cover the ranges (one for each quadrant). At that point it's probably better to either upgrade or use IA's solution of drawing the axes manually instead.

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


Image Analyst
Image Analyst 2016년 7월 2일
I don't know how. But it's easy to draw lines there.
line(xlim, [0,0], 'LineWidth', 2, 'Color', 'k');
line([0,0], ylim, 'LineWidth', 2, 'Color', 'k');
Removing tick marks and labels and moving them to those new axes you just drew would be more complicated. Perhaps just having the thick lines for the axes would be good enough.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by