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 日

0 投票

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

1 件のコメント

Mahum Farhan
Mahum Farhan 2021 年 3 月 20 日
thank you so much!! you're a lifesaver :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData 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