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

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

采纳的回答

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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by