MATLAB Answers

Info

This question is closed. Reopen it to edit or answer.

Zoom out problem with two x-linked axes containing data in different ranges

1 view (last 30 days)
Soren Preus
Soren Preus on 31 Oct 2012
Closed: MATLAB Answer Bot on 20 Aug 2021 at 16:28
Hi all
I have a zoom problem when plotting in two x-linked axes and would be very happy for any suggestions to solve the problem.
Here's an example:
x1 = 5:10;
y1 = 5:-1:0;
x2 = 0:10;
y2 = 0:10;
hl1 = line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);
linkaxes([ax1 ax2],'x')
The problem in the resulting plot is that xlim goes from 5-10 and not 0-10 as it should. Even when I try to zoom out the zooming only goes as far as xlim([5 10]) thus leaving out some of the (x2,y2)-data in the plot.
When plotting (x1,y1) in ax2 and (x2,y2) in ax1 the problem no longer exists, however, I would like to find a different solution as this solution is not really an easy implementation in my actual application.
Any suggestions are appreciated.
Best, SP

Answers (0)

Community Treasure Hunt

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

Start Hunting!