From: daffidity on
Hi,

Does anyone know a simple way of putting the xlabels between the tick marks please? That question has been asked before but I cannot find a solution that works.

The .m file by m vichi (see below) works but also messes up my y labelling

function ax2 = ticklabel(ax1)
% TICKLABEL Shift the tick labels in the X axis
% TICKLABEL(AX) shifts current ticklabels to the right
%between
% tick marks in axis AX. It only works for the X axis.
% Returns the handler to the hidden axis with the
%centered ticklabels.

% Author M. Vichi (CMCC), from ideas posted on the Mathworks
%forum

if nargin==0, ax1=gca; end

ax2=axes('position',get(ax1,'position'));

%invert the order of the axes
c=get(gcf,'children');
set(gcf,'children',flipud(c))

xlim=get(ax1,'XLim');
xtick=get(ax1,'XTick');
delt=diff(xtick);
xtick2=[0.5*[delt delt(end)]+xtick(1:end)];
xticklabels=get(ax1,'XTickLabel');
set(ax2,'Xlim',xlim,'XTick',xtick2,'XTicklabel',xticklabels);
ytick=get(ax1,'YTick');
yticklabels=get(ax1,'YTickLabel');
set(ax2,'Ylim',ylim,'YTick',ytick,'YTicklabel',yticklabels);
set(ax1,'XTickLabel','','Visible', 'on')

I would very much appreciate an alternative.

D