MATLAB: Upper axis title doesn’t fit in the output of the plot

matlab plot -plot with 2 x axis-2 x axis titles

hello everyone
i m plotting a graph on one Y axis and 2 X axis
each X axis has a title
the title shows on the bottom axis however it doesnt show on the upper axis (it seems to be truncated by the size of the paper.
(the only way to show it is to change completely the proportion of my plot (instead of 18×12 cm it should be 18×16 or so..)
any hint on how to fit the upper axis title while keeping the same horizontal proportion?
code below:
set(gcf,'units','centimeters','outerposition',[2 2 18 12]);
set(gcf,'units','centimeters','paperposition',[0 0 18 12]);
set(gca,'yscale','log');
set(gca,'xscale','linear');
ax1 = gca; % current axes
ylabel(['mass fraction','%']);
xlim([0.0,1.4]);
ylim([0.0001,1]);
yticklabels([ 0.01 0.1 1 10 100]);
xlabel(['enclosed mass','[M', solar,']']);
legend( 'Location', 'Southwest' );
legend boxoff;
set(gca,'box','off')
set(legend,'FontSize',8);
set(gca,'linew',1.2)
solar = char(9737);
Ang=char(197);
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
xlim([0.0,1.4]);
xticks([0.185 0.316 0.6 0.837 1.085 1.24 1.36 ]);
xticklabels([3800 5000 7500 10000 12500 15000 17500 ]);
set(gca,'yscale','log');
ylim([0.0001,1]);
yticklabels([ ]);
set(gca,'linew',1.2)
xlabel(['velocity','[km s^{-1}]']);

Best Answer

Reduce the height of the first axis
% This reduced the height to 80%
% Play around with the value to get what you want
ax1.Position(4) = ax1.Position(4)*.80;
Then link the ax1 and ax2 axes.
linkaxes([ax1,ax2])