필터 지우기
필터 지우기

linkaxes(ax,'x') + candle() + automatic adjustment of y limits of subplots

조회 수: 1 (최근 30일)
Herwig Peters
Herwig Peters 2012년 10월 20일
댓글: Herwig Peters 2017년 7월 4일
I have a figure with two subplots, which share the same x range but have very different y ranges. I link the x axes with linkaxes(ax,'x'). If I zoom in on, say, the second subplot, the x limits on both plots are changed simultaneously. However, the y limits on the first plot are too wide now, hence I'd like Matlab to do an automatic adjustment/zoom of the y limits for the first subplot. I'd use
linkaxes(ax,'x')
set(ax,'ylimmode','auto')
and the ylims should be reset automatically every time I zoom in on any subplot. But... Matlab doesn't adjust YLim correctly. How can I fix this?
EDIT: In one of the subplots, I call the function candle(). This seems to cause the problems. When I replace candle() by plot(), everything is ok. How to make this work with candle()?

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 20일
x=0:0.1:10;
ax(1)=subplot(2,1,1);
ax(2)=subplot(2,1,2);
plot(ax(1),t,sin(2*t))
plot(ax(2),t,2*sin(t))
linkaxes(ax,'x')
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 20일
why don't you post your code?
Herwig Peters
Herwig Peters 2012년 10월 20일
Ok, I've created a small example. Try zooming in on the second plot around x=500.
clear ax
n = 1000;
P.trend = [linspace(1,8,n/2)';linspace(8,2,n/2)'];
P.high = P.trend+rand(n,1);
P.low = P.trend+rand(n,1);
P.close = P.trend+rand(n,1);
P.open = P.trend+rand(n,1);
I.trend = linspace(7,3,n)';
I.high = I.trend+rand(n,1);
I.low = I.trend+rand(n,1);
I.close = I.trend+rand(n,1);
I.open = I.trend+rand(n,1);
ax(1) = subplot(2,1,1);
candle(P.high,P.low,P.close,P.open)
ax(2) = subplot(2,1,2);
candle(I.high,I.low,I.close,I.open)
linkaxes(ax,'x')
set(ax,'ylimmode','auto')

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


Ziad Sliti
Ziad Sliti 2017년 7월 4일
You just have to remove the command :
axis([xmin xmax ymin ymax])
and axis will be adjusted automatically.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by