# Reducing number of ticks

Is there any way to quickly reduce the number of ticks without having to specify them all yourself? There are too many ticks in my plot to show them properly (in a small graph I use to inset into another graph). There is especially no room for accompanying numbers. Say I would like to keep only half the number of ticks (or only show the numbers for half of the ticks), is this possible without having to specify the exact position of all of them?

Edit:

   myticksX[min_, max_, n_, tickLen_] :=
Module[{},
ticks = Table[{i, i, {tickLen, 0}}, {i,
FindDivisions[{min, max}, n]}];
ticks[[2 ;; -2 ;; 2]] =
ticks[[2 ;; -2 ;; 2]] /. {a_?NumericQ,
b_?NumericQ, {tickLen, 0}} :> {a, "", {tickLen, 0}};
ticks];
myticksY[min_, max_, n_, tickLen_] :=
Module[{},
ticks = Table[{i, i, {0.01, 0}}, {i, FindDivisions[{min, max}, n]}];
ticks[[2 ;; -2 ;; 2]] =
ticks[[2 ;; -2 ;; 2]] /. {a_?NumericQ,
b_?NumericQ, {tickLen, 0}} :> {a, "", {tickLen, 0}};
ticks];
Plot[Sin[x], {x, 0, 10}, Frame -> True,
FrameTicks -> {{myticksY[-1, 1, 4, 0.01],
None}, {myticksX[0, 10, 5, 0.01], None}}]


myticksX[min_, max_, n_] :=
Table[{i, i, {0.01, 0}}, {i, FindDivisions[{min, max}, n]}]
myticksY[min_, max_, n_] :=
Table[{i, i, {0.01, 0}}, {i, FindDivisions[{min, max}, n]}]
Plot[Sin[x], {x, 0, 10}, Frame -> True,
FrameTicks -> {myticksX[0, 10, 5], myticksY[-1, 1, 5]}]


Or

Plot[Sin[x], {x, 0, 10}, Frame -> True,
FrameTicks -> {{myticksY[-1, 1, 3], None}, {myticksX[0, 10, 3],
None}}]


• Great! Thanks (and without undocumented functions the danger of which you pointed out in your comment). Would it be simple to also add smaller unnumbered ticks in between (but keeping the spacing equal between all of them)? – Kvothe Apr 25 '19 at 14:53

You could use ChartingScaledTicks instead of Automatic:

Plot[Sin[x], {x, 0, 2 Pi}, Ticks -> {
ChartingScaledTicks[{Identity,Identity}][##, {3, 3}]&,
ChartingScaledTicks[{Identity,Identity}][##, {3, 3}]&
}
]


or:

Plot[Sin[x], {x, 0, 2 Pi},
Frame->True,
FrameTicks -> {
{
ChartingScaledTicks[{Identity,Identity}][##, {3,3}]&,
ChartingScaledFrameTicks[{Identity,Identity}][##, {2, 2}]&
},
{
ChartingScaledTicks[{Identity,Identity}][##, {2, 2}]&,
ChartingScaledFrameTicks[{Identity,Identity}][##, {2, 2}]&
}
}
]
`

• I am not getting your img with my version 12.0.0 for Microsoft Windows (64-bit) (April 6, 2019) – OkkesDulgerci Apr 25 '19 at 14:27
• @Carl, thanks! Any idea how I can keep the spacing even between ticks though? (Compare the spacing with {3,3} to no Ticks option. The big spacing does not coincide with the small one anymore.) – Kvothe Apr 25 '19 at 14:33
• @Okkes Does my update produce the same output in M11 and M12 for you (other than the decimal point)? – Carl Woll Apr 25 '19 at 14:42
• @Kvothe Sorry, I don't understand what spacing you're talking about. – Carl Woll Apr 25 '19 at 14:42
• @Carl, sorry I should have been more clear I guess. If you run this without a ticks option you will see that all ticks have equal spacing between them. If we reduce the amount of ticks using your option we see that the "bigger" spacing falls in between the smaller (unnumbered) ones so that the spacing is not equal between that and the others. I would prefer to take out ticks in such a way that this distance is also equal. I think that looks nicer. (of course that is asking a lot and I am already grateful for being able to reduce the number of ticks in a simple manner). – Kvothe Apr 25 '19 at 14:47