How do I add minor ticks to a graph?

866 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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.

更多回答(1 个)

Matt
Matt 2014-11-15
编辑:Matt 2014-11-15
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 个评论
Walter Roberson
Walter Roberson 2018-11-1
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 2019-4-9
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by