EkEhsaas
EkEhsaas

Reputation: 93

How to make more tick marks appear in graph?

I want more tick marks appear in graph. For example, if I do this: plot(1:1000), I get the following:

original

How to make more tick marks appear as shown at the X-axis of the following figure? wanted

I want to do the same for Y-axis. Customizing this is not documented.

Upvotes: 1

Views: 412

Answers (2)

EBH
EBH

Reputation: 10440

If you have MATLAB 2016a or later you can use the Ruler properties:

plot(1:1000);
ax = gca;
ax.YMinorTick = 'on';
ax.YAxis.MinorTickValuesMode = 'manual'; % prevents MATLAB form update it
tick_gap = ax.YAxis.TickValues(2)-ax.YAxis.TickValues(1);
minor_tick_no = 5;
minor_gap = tick_gap/minor_tick_no;
ax.YAxis.MinorTickValues = ax.YAxis.TickValues(1)+minor_gap:...
    minor_gap:ax.YAxis.TickValues(end);

minor_tick

And the same for the ax.XAxis property.

Upvotes: 1

rayryeng
rayryeng

Reputation: 104503

For more recent versions of MATLAB you simply grab the axes and change the YMinorTick property to 'on':

plot(1:1000);
ax = gca;
ax.YMinorTick = 'on';

For older versions, you have to grab the axes using the set function:

plot(1:1000);
set(gca, 'YMinorTick', 'on');

We get:

enter image description here

Upvotes: 2

Related Questions