# Evenly spaced Tick marks for Primes

I'm trying to have the integers evenly spaced on the x axis of a ListPlot, and the prime numbers evenly spaced on the y axis.

maxPrimeIndex = 25;
maxPrime = Prime[maxPrimeIndex];
Flatten[(Partition[
Riffle[Flatten[FactorInteger[#]][[;; ;; 2]], #, {1, -2, 2}], 2]
) & /@ Range[2, maxPrime], 1];
ListPlot[%,
Ticks -> {Automatic, Prime[Range[1, maxPrimeIndex]]},
PlotRange -> {{0, maxPrime}, {0, maxPrime}}
]


Which gives:

How can I get the y axis to be evenly spaced?

• "prime numbers" and "evenly spaced" sounds like incompatible conditions. What exactly are you envisioning here? Jun 7, 2020 at 16:19
• Is it impossible to evenly space an arbitrary set? I'm just messing around; visualizing how many divisors there are around certain primes. Jun 7, 2020 at 16:20
• In the case of the primes, the spacing not being regular is well-known. Jun 7, 2020 at 16:23
• If your points are only primes you can try adding ScalingFunctions -> {PrimePi, Prime} option to ListPlot. Jun 7, 2020 at 16:23
• @J.M.'stechnicaldifficulties But whether or not there are infinite spacings of 2 or 4 or 220 are unknown. Jun 7, 2020 at 16:24

As people on the comments pointed out this may be a problematic in various ways, but if all y-values of your points are primes, this can be accomplished with ScalingFunctions option. PrimePi is an inverse of the Prime function, and you list both to guide ListPlot:

maxPrimeIndex = 25;
maxPrime = Prime[maxPrimeIndex];
Flatten[(Partition[
Riffle[Flatten[FactorInteger[#]][[;; ;; 2]], #, {1, -2, 2}], 2]
) & /@ Range[2, maxPrime], 1];
ListPlot[%,
Ticks -> {Automatic, Prime[Range[1, maxPrimeIndex]]},
PlotRange -> {{0, maxPrime}, {0, maxPrime}},
ScalingFunctions -> {PrimePi, Prime}]


You can also map PrimePi on the second column of input data and change the vertical axis tick labels using custom ticks:

maxPrimeIndex = 25;
maxPrime = Prime[maxPrimeIndex];

data  = Flatten[
Partition[Riffle[Flatten[FactorInteger[#]][[;; ;; 2]], #, {1, -2, 2}], 2] & /@
Range[2, maxPrime], 1];

ListPlot[MapAt[PrimePi, data, {All, -1}],
Ticks -> {Automatic,
Thread[{Range @ maxPrimeIndex, Prime @ Range @ maxPrimeIndex}]},
PlotRange -> {{0, maxPrime}, {0, maxPrimeIndex}}]


• Yeah, this alternative came to my mind too. I wonder if there are cases where these solutions are not effectively identical. Certainly it's of pedagogical value to point out that tick labels don't need to correspond their actual coordinate values! Jun 8, 2020 at 4:44