How do keep multiple axes (with title) aligned during paper resizing?

4 views (last 30 days)
I'm using MATLAB 2015a and trying to create a figure with two x-axes, two x-labels, and a title. It works quite well except I cannot have the title visible and the figure resizeable at the same time. Here is the code I'm using at the moment (Title is off-figure):
plot(phossimx,phossimy/(max(phossimy)-min(phossimy)),'Linewidth',1); %This is my data, scaled arbitrarily
xlabel('Field (T)');
xlim([2 5.5]);
ylim([-1 0.6]);
ylabel('d\chi"/dB');
gaxis=planck*(Exp.mwFreq*10^9)./(bmagn*phossimx); %This is used to calculate axis 2
ax1=gca;
ax1_pos=ax1.Position;
set(gca,'YTickLabel','');
ax2=axes('Position',ax1_pos,'XAxisLocation','top',...
'XLim',[gaxis(end) gaxis(1)],'XDir','reverse',...
'YTickLabel','','YAxisLocation','right',...
'Color','none');
ax2.XLabel.String='\itg'; %top axis label
ax2.XLabel.FontSize=10; %top axis font size
ax2.YTick=ax1.YTick; %Match right axis with left axis
ax2.YLim=ax1.YLim;
ax2.Title.String='Co-P_i Sim at 130GHz'; %Title. if use ax1.Title.String, title is placed over ax2.XLabel
I've tried adding in ActivePositionProperty flags, and if I do
ax2.ActivePositionProperty='OuterPosition';
ax2.ActivePositionProperty='OuterPosition';
The second axis changes to the correct position, however the first remains in place, essentially misaligned axes. If I do a "hotfix" by adding in some arbitrary OuterPosition definition for ax1; i.e.
ax1.OuterPosition=[0 0 1 0.899];
It will draw the figure with matching axes, however upon rescaling it immediately becomes offset again.
Does anyone have an idea on how to make it so I can make this figure behave well with rescaling?

Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!