Two X axes with different directions
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
dpb
on 18 Oct 2022
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 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!