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
채택된 답변
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 Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!