For example, if we have a time series of 365 values, I would like to
obtain a plot with "13 Xticks" and "12 Xticklables": each Xticklabel
should be in between two Xticks (for example the Xticklabel "January"
should be in between the Xtick "1" and the Xtick "31"). I've tried
with:
%========================================
close all
clear all
monthlim=[1,31,59,90,120,151,181,212,243,273,304,334,365]; %13
Xticks.
xticklabels=['J';'F';'M';'A';'M';'J';'J';'A';'S';'O';'N';'D']; %12
XtickLabels.
y=rand(1,365);
plot([1:365],y)
set(gca,'Xlim',[1,365],'XTick',monthlim,'XTicklabel',xticklabels)
grid on
%========================================
...But this can never work since I am using the same position for the
"Xticks" and for the "Xticklabels".
Anybody know how to resolve this problem?.
I would realy apreciate any help or sugestion.
Than you for your time!
Serval.
You are going to have to use textbox uicontrols and place them where
you want. Check out the following file on the FEX:
<http://www.mathworks.com/matlabcentral/files/8722/rotateticklabel.m>
It is a good example of how to replace labels with text boxes.
I remember have seen a web page explaining how to do it without using
"text" command, but I can not find it again...
It is strange anyway that this feature is not included as an option
in Matlab.
Cheers,
Serval.
.........................
I get the impression they are adding things as fast as they can.
Contact the tech support, and request an enhancement to allow placing
ticklabels at locations other than the ticks.
<http://www.mathworks.com/support/service_requests/contact_support.do>
This will show them that there is at least one customer who is
interested in this functionality.
See You.
S.
..........................................
%=============================================
close all
clear all
monthlim=[1,31,59,90,120,151,181,212,243,273,304,334,365];
monthlim2=0.5*diff(monthlim)+monthlim(1:end-1);
xticklabels=['J';'F';'M';'A';'M';'J';'J';'A';'S';'O';'N';'D'];
y=rand(1,365);
figure(1)
ax(1)=newplot;
set(gcf,'nextplot','add');
set(ax(1),'Xlim',[1,365],'XTick',monthlim2,'XTicklabel',xticklabels);
ax(2)=axes('position',get(ax(1),'position'),'Visible', 'off');
plot(1:365,y)
set(ax(2),'Xlim',[1,365],'XTick',monthlim,'XTicklabel','');
grid on
%=============================================
Serval.
...............................
Ah, good idea. Use the labels of a second axis underneath the first.
It now works on an already existing axis
cheers
marcello
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')