how do I add a second x-axis label below existing one instead of plotting two figures ?

186 ビュー (過去 30 日間)
I've written a code (SteelPlateThicknessParam4Help) which uses 2 functions (attahced also) - should be in the same directory.
The main output is 2 plots, which differ in their x-axis (attahced the photos).
How can I plot these different scaled x-axis on one plot instead of two ?
Irad
  2 件のコメント
Irad Brandys
Irad Brandys 2023 年 8 月 17 日
Thanks for the answer. Already saw that link, but I wish the result to be like:

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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 8 月 17 日
%Minimum working example solution for differently scaled x-axis with similar range of y-values
%Adjust/Modify properties as necessary (font size, xticks, etc)
x1 = [1 2 3 4 5];
x2 = [0.1 0.2 0.3 0.4 0.5];
y = rand(2, 5);
%This generates values between 0 and 1
%i.e both columns have similar range of values
%% Use multiple axes
%1st axes and plotting
ax1 = axes('Position', [0.15 0.2 0.775 0.715]);
p1 = plot(ax1, x1 , y(1,:), 'r*-');
xlabel('X1 label')
%Add another axes at the same position and plot
ax2 = axes('Position', ax1.Position);
p2 = plot(ax2, x2 , y(2,:), 'bo-');
ax2.Color ='none';
ax2.YTick=[];
ax2.YTickLabel=[];
xlabel('X2 label')
%Adjust tick label location for the 2nd axes
ax2.XRuler.TickLabelGapOffset=33;
%link the axes
linkaxes([ax1, ax2], 'y')
%Add common legend for both plots by combining plot handles
legend([p1;p2],'a','b')
  3 件のコメント
Irad Brandys
Irad Brandys 2023 年 8 月 19 日
Dear Joshi,
Thank you very much for the example.
Much more clear now and works well for me.
Irad
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 19 日
If my answer helped you, please consider accepting it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by