Two X axes with different directions
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi All, I need to make a plot with Two X axes with different directions (axes below)
x1 = 1:20; % axis in tau scale
x2 = x1.*(128/3); % axis in ms to s /1000
x3 = 1./(x2./1000); % axis in Hz
So the same Y values will be plotted against x2 (axis at the bottom from smallest to highest) and x3 (axis at the top from highest to smallest). Unfortunately I haven't managed to get the desired output by fdoing the following:
figure
h1 = axes
plot(x2,mean(MS_LUM_EO_FS_F(:,ini:fin)),'r'); hold on
set(h1, 'XAxisLocation', 'bottom')
h2 = axes
plot(x3,mean(MS_LUM_EO_FS_F(:,ini:fin)),'r'); hold on
set(h2, 'Xdir', 'reverse')
set(h2, 'XAxisLocation', 'top')
Any suggestions, help on how to do it?
댓글 수: 0
답변 (1개)
dpb
2022년 10월 18일
x1 = 1:20; % axis in tau scale
x2 = x1.*(128/3); % axis in ms to s /1000
x3 = 1./(x2./1000); % axis in Hz
figure
hL=plot(x2,randn(size(x2)),'r');
hAx=gca;
hAx(2)=axes('Position',hAx(1).Position, ...
'XAxisLocation','top', ...
'Xdir', 'reverse', ...
'YAxisLocation','right', ...
'Color','none');
hL(2)=line(hAx(2),x3,randn(size(x3)),'Color','k');
The key thing you missed is the 'Color','none' so the second axes doesn't occlude the first.
The second requirement is either use the low-level drawing primitives such as line or (you did, just noting) set hold on or plot and the other higher-level routines will still do all their initial house-cleaning and wipe out much of what you just spent all that effort on creating...
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!