Can I plot rectangles without rescalling axis limits?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
Risposta accettata
Matt Fig
il 25 Set 2012
Modificato: Matt Fig
il 25 Set 2012
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!