# Custom frame ticks in listplot

i am trying to ListPlot some data extracted from the approximation of a complicated function. The minimal code is the following

 pl[m_, n_] := ListPlot[f[m, n], PlotStyle -> Automatic, Frame->True, FrameTicks -> {{Automatic, None}, {{{1, m},{2,m+1},{3,m+2},{4,m+3},{5,m+4},{6,m+5},{7,m+6},{8,n}}, None}}]

The code will not run as I have not provided the function f[m,n] here. Why the plot is defined like that? The reason is I have to generate many plots just by changing the value of m, n. Please look at the FrameTicks FrameTicks -> {{Automatic, None}, {{{1, m},{2,m+1},{3,m+2},{4,m+3},{5,m+4},{6,m+5},{7,m+6},{8,n}}, None}}, where it can be seen that I want to relabel the frameticks that way. The m value need not to be start from 1 always. The issue is if I increase the number of ticks say between 10 & 100, I have to put 91 pairs {i,m+i-1} (in this case) using my approach as I understand that my approach is a sort of manual. The question is how I can adjust these ticks automatically starting from prechosen m and ending at n with a step size of my choice, e.g. 1 or 2 or 5 etc. I searched on the web, but unfortunately, I didn't see any match understandable to me. Help is needed in this regard, please.

• Instead of an explicit list, you can create a Table: Table[{i, m + i - 1}, {i, 1, n}]? I am not sure if I understood your rules are for generating the ticks though. Commented May 25, 2022 at 15:52
• Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
– Community Bot
Commented May 25, 2022 at 15:58
• @Community for pl[4,15], how the FrameTicks can be adjusted to be of the form 3, 4, 5, 6, ..., 15? I mean to start from 3 and end at 15. I need an automated code that should work for pl[6,20], pl[3,30] etc. Commented May 25, 2022 at 22:19
• e.g., m = 4; n = 9; and Table[{i, If[i == m, "m" , If[i == n, "n", "m+" <> ToString[i - m] ]] }, {i, m, n} ] could be used as x-ticks.
– Syed
Commented May 26, 2022 at 6:24
• @Syed Can't it take the values of m and n from pl[m,n] automatically? Commented May 26, 2022 at 13:12

Are you looking for something like this (I introduced a local variable for clarity, and I replaced f[m,n] so I could see an actual plot)?

pl2[m_, n_] :=
With[
{ticks = Table[{i, i + m - 1}, {i, 1, n - m}]},
ListPlot[ticks, PlotStyle -> Automatic, Frame -> True,
FrameTicks -> {{Automatic, None}, {ticks, None}}]]


Since you might want to control the spacing between ticks, it might be good to introduce another argument, like this:

pl2[m_, n_, step_] :=
With[
{ticks = Table[{i, i + m - 1}, {i, 1, n - m, step}]},
ListPlot[ticks, PlotStyle -> Automatic, Frame -> True,
FrameTicks -> {{Automatic, None}, {ticks, None}}]]