How to make a plot with upper x-axis adapted to the scale of the lower x-axis

5 ビュー (過去 30 日間)
Francesca Turco
Francesca Turco 2025 年 3 月 9 日
回答済み: Walter Roberson 2025 年 3 月 9 日
Hello, I'm trying to make a plot with two x-axex, one on the top and one on the bottom, referring to the same curve in the figure. I can make the top axis by plotting a dummy curve with no line, but of course that aligns the top axis to that curve, not to the bottom axis scale. I attach an example of the results below. The snippet of the code I am using is this:
figure(99); plot(xxp,Paux_H98tot_series,'-sk','markersize',10,'linewidth',3)
hAx(1)=gca;
hAx(2)=axes('Position',hAx(1).Position,'XAxisLocation','top','YAxisLocation','right','color','none'); hold(hAx(2),'on')
plot(hAx(2),fnGmodel_series,Paux_H98tot_series,'-ob'); set(hAx(2),'yticklabel',{});
The thin blue curve is only the dummy that allows me to create a separate x-axis on the top and it will have a "no line" so it will disappear. But of course the top axis aligns with this curve now, and it does not give the correct values for the black curve.
What I need is the top axis to align with the black curve (the only one that will remain in the final plot), so the ticks and scale should move to the right, basically.
Is there a way to make this kind of plot with the top x-axis that refers to the values of the bottom axis, moving the ticks and scales of the axis instead of the curve?

回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 3 月 9 日
Sounds like a job for linkaxes

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by