How do I add minor ticks to a graph?

929 views (last 30 days)
I would like to add minor ticks in between the major ticks. I would like to know if there is a function or a property which will allow me to do this.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 May 2012
There are three properties of axes that allow you to add minor ticks to the axes. They are:
Property NameProperty Values
------------- ---------------
XMinorTick[on,{off}]
YMinorTick[on,{off}]
ZMinorTick[on,{off}]
Below is an example of how to use them:
plot(1:10)
set(gca,'XMinorTick','on','YMinorTick','on')
It is not possible to specify the location of the minor tick marks. Refer to the related solution for a workaround.

More Answers (1)

Matt
Matt on 15 Nov 2014
Edited: Matt on 15 Nov 2014
Note that as of 2014B it looks like you should be able to edit the location of the minor tick marks directly. This only seems to work though if the minor ticks are already showing.
hA = gca;
%Tick properties can be set in the X/Y/ZRuler.MinorTicks
hA.YRuler.MinorTicks
%Tick locations can be set in the X/Y/ZRuler.MinorTick
hA.Yruler.MinorTick = [0.1:0.1:0.9]
  2 Comments
Walter Roberson
Walter Roberson on 1 Nov 2018
That property is still available in R2018b, for all four regular ruler types (numeric, duration, datetime, categorical).
The property is not available for map axes. It is not immediately clear to me what the map axes equivalent would be.
The property is not exactly available for polaraxes, because polaraxes have RAxis and ThetaAxis rather than XAxis and YAxis. However, RAxis and ThetaAxis both have MinorTickValues properties.
KAE
KAE on 9 Apr 2019
Here is an example that worked for me in R2019a,
figure;
plot(rand(10,1), rand(10,1), '.'); % Example plot
h = gca; % Get axis to modify
h.XAxis.MinorTick = 'on'; % Must turn on minor ticks if they are off
h.XAxis.MinorTickValues = -1:0.03:1; % Minor ticks which don't line up with majors

Sign in to comment.

Categories

Find more on Polar Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!