%% Change Axis Tick Values 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.
% 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 tick values by setting the XTick and YTick properties of the axes object. 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 set 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. If you do not specify enough labels for all the tick values, then the axes cycles through the labels. Use the TeX markup \pi for the \pi symbol.

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',{'-3pi','-2pi','-pi','0','pi','2pi','3pi'}) 
% 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;

% Copyright 2012 The MathWorks, Inc.