필터 지우기
필터 지우기

Can I plot rectangles without rescalling axis limits?

조회 수: 5 (최근 30일)
Razvan
Razvan 2012년 9월 25일
Hi,
I try to plot a function and to mark some locations using rectangle. I use
pan xon
to be able to pan, and the y axes rescale automatically (if I don't put the rectangles). How can I tell Matlab to disregard the rectangles when rescalling. I want the rectangles to mark vertical strips along the whole ylim domain (which adjusts as I pan). If this is not possible are there other elements (e.g. line or something else) which don't rescale the axis limits?
Thanks,
Razvan
EDIT: Here is an example:
x = 1:1000;
figure
ax(1) = subplot(211);
% hold on
% for pos = 100:100:1000
% rectangle('Position', [pos -1000 5 2000], 'FaceColor',[0.5 1 0.5])
% end
plot(x .* sin(x));
xlim([51 100])
ax(2) = subplot(212);
plot(sin(x));
xlim([51 100])
linkaxes(ax, 'x');
pan xon
If the rectangles are not plotted, then I can pan the lower panel and the y axis of the top panel rescales automatically. (By the way if I pan the top panel the y limit adjustments don't work anymore...)
I want to obtain the same effect but with the marked regions visible. Please uncomment the rectangle part and see that now the y axis has the limits fixed by the rectangle dimensions. I want this to rescale according to the function alone (disregarding the rectangles). Is this possible?

채택된 답변

Matt Fig
Matt Fig 2012년 9월 25일
편집: Matt Fig 2012년 9월 25일
You need to post complete example code. I see no problems with this:
ezplot(@sin)
hold on
rectangle('Position', [.2 sin(.2) .1 .1])
pan xon % No move the axes back and forth...
.
.
.
EDIT In response to the edited question
Does this do what you want:
x = 1:1000;
figure
ax(1) = subplot(211);
hold on
for pos = 100:100:1000
rectangle('Position', [pos -1000 5 2000], 'Facec',[0.5 1 0.5])
end
xlim([51 100])
ax(3) = axes('pos',get(ax(1),'pos'));
plot(x .* sin(x));
xlim([51 100])
set(ax(1),'xtick',[],'ytick',[])
set(ax(3),'color','none')
ax(2) = subplot(212);
plot(sin(x));
xlim([51 100])
linkaxes(ax, 'x');
pan xon
  댓글 수: 3
Matt Fig
Matt Fig 2012년 9월 25일
Please see my edited answer.
Razvan
Razvan 2012년 9월 25일
Thank you. Nice trick! Good to know.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by