%% Change Axis Tick Value Locations and Labels
% This example shows how to change the tick value locations and associated
% labels for the _x_-axis and _y_-axis. It also shows how to rotate the
% labels.

% Copyright 2015 The MathWorks, Inc.


%% 
% Create |x| as 200 linearly spaced values between -10 and 10. Create |y|
% as the cosine of |x|. Plot the data.

x = linspace(-10,10,200);
y = cos(x);
plot(x,y)

%%
% Change the locations of the tick values by setting the |XTick| and
% |YTick| properties of the axes. Set each property as a vector of
% increasing values. The values do not need to be equally spaced.
%
% *Note:* Starting in R2014b, you can use dot notation to set properties.
% If you are using an earlier release, use the
% <docid:matlab_ref.f67-432995> function instead, such as
% |set(ax,'YTick',[-1 -0.5 0 0.5 1])|.

ax = gca; 
ax.XTick = [-3*pi -2*pi -pi 0 pi 2*pi 3*pi]; 
ax.YTick = [-1 -0.5 0 0.5 1]; 

% For R2014a and earlier: 
% ax = gca; 
% set(ax,'XTick',[-3*pi -2*pi -pi 0 pi 2*pi 3*pi]) 
% set(ax,'YTick',[-1 -0.5 0 0.5 1]) 

%% 
% Specify the associated labels by setting the |XTickLabel| and
% |YTickLabel| properties of the axes. If you do not specify enough
% text labels for all the tick values, then the axes cycles through the
% labels.

ax.XTickLabel = {'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'}; 
ax.YTickLabel = {'min = -1','-0.5','0','0.5','max = 1'}; 

% For R2014a and earlier: 
% set(ax,'XTickLabel',{'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'}) 
% set(ax,'YTickLabel',{'min = -1','-0.5','0','0.5','max = 1'}) 

%% 
% Rotate the labels by setting the |XTickLabelRotation| and
% |YTickLabelRotation| properties of the axes. 

ax.XTickLabelRotation = 45;
ax.YTickLabelRotation = 45;