how to create a second x axis with different intervals?

Hiya! I've been looking at similar questions but haven't been able to make the code work myself. I'm trying to make a scatter plot for examining fluxes with depth, where the y axis is depth, one x axis is lipid fluxes and the second x axis is carbon flux. I need the two x axes to have a different interval range. I've managed to get the first x axis but for some reason the second won't show up. This is the code I have so far:
scatter(fame1,depth1,'^')
set(gca, 'YLim',[-750 -100])
ax= gca;
ax1= ax;
ax2= ax;
ax2.XAxisLocation= 'bottom';
set(ax1, 'XAxisLocation', 'top')
set(ax1,'XTick',([0:0.25:3]));
set(ax2, 'XAxisLocation', 'bottom')
set(ax2,'XTick',([0:5:25]));
How can I get the second x axis on the bottom to show up?? Any help would be appreciated!

 채택된 답변

dpb
dpb 2021년 3월 20일
편집: dpb 2021년 3월 20일
You've actually got three copies of the one axes handle (ax,ax1,ax2); you've never created a second axes.
hSc=scatter(rand(10,1)*2,randi([-720 -120],10,1),'^')
hAx1= gca;
hAx1.YLim=[-750 -100];
xticks(hAx1,[0:0.25:3])
hAx1.XAxisLocation= 'top';
hAx2=axes('position',hAx1.Position,'color','none');
hAx2.XAxisLocation='bottom';
xticks(hAx2,[0:5:25])
hAx2.YTick=[];
xlim(hAx2,[0 25])
box on
results in

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2021년 3월 20일

편집:

dpb
2021년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by