Reputation: 93
I want more tick marks appear in graph. For example, if I do this: plot(1:1000)
, I get the following:
How to make more tick marks appear as shown at the X-axis of the following figure?
I want to do the same for Y-axis. Customizing this is not documented.
Upvotes: 1
Views: 412
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);
And the same for the ax.XAxis
property.
Upvotes: 1
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:
Upvotes: 2