Effacer les filtres
Effacer les filtres

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

124 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 17 Août 2023
%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 commentaires
Irad Brandys
Irad Brandys le 19 Août 2023
Dear Joshi,
Thank you very much for the example.
Much more clear now and works well for me.
Irad
Dyuman Joshi
Dyuman Joshi le 19 Août 2023
If my answer helped you, please consider accepting it.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by