Two X axes with different directions

3 次查看(过去 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?

回答(1 个)

dpb
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...

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by