# Ticks in v10 - a bug or undocumented change

Bug introduced in 10.0 and fixed in 10.4

In this post @Heike provides this code:

ticksfun[xmin_, xmax_] :=
Table[{10^i, Superscript[10, i]}, {i, Floor[Log10[xmin]],
Ceiling[Log10[xmax]]}]

LogLogPlot[Log[x!], {x, 1, 10^5},
PlotRange -> {{0, 10^5}, {10^-1, 10^6}},
Ticks -> {ticksfun, ticksfun}]


This works perfectly in v9.:

But in v10, it does not:

The error is:

Tick specification must be a list or a function


The help page for Ticks looks identical in v10 and v9. So the main question, is this a bug or is there an undocumented change in v10?

Note: Ticks in Plot seems to work relatively ok in v10.

## Update

Based on the analysis provided by @rcollyer, I did some tests between Mathematica v9 and v10:

minmax = {};
ticksfun[xmin_, xmax_] := Module[{i},
minmax = {xmin, xmax};
Table[{10^i, Superscript[10, i]},
{i, Floor[Log10[xmin]], Ceiling[Log10[xmax]]}]
];
minmax2 = {};
ticksfun2[xmin_, xmax_] := Module[{i},
minmax2 = {xmin, xmax};
Table[i, {i, Floor[xmin], Ceiling[xmax]}]
];


Then I run:

LogLogPlot[x^2, {x, 1, 10}, Ticks -> {ticksfun, ticksfun}]
Plot[x^2, {x, 1, 10}, Ticks -> {ticksfun2, ticksfun2}]


The first plot has error, the second is ok, fine, so what does Mathematica v9 return on minmax:

In[13]:= minmax
minmax2

Out[13]= {1., 100.}

Out[14]= {-2.08333, 102.083}


What does Mathematica v10.4 return on minmax?

In[101]:= minmax
minmax2

Out[101]= {-0.511686, 5.11686}

Out[102]= {-5.55556, 105.556}


I am not experienced in the internals of Mathematica but all this suggests that there is a change in what the plotting functions are sending to ticks fucntions. And notice the change is not only in LogLogPlot but in Plot as well. I think Mathematica should not be passing negative numbers in LogLogPlot.

## Update 2

When I tried to implement the solution by @rcollyer, I realized, it is necessary to to further conversions. The solution posted at the bottom creates wrong descriptions of the axis --- the ticks are misplaced. The problem is that the range is supplied in natural logarithm while, we are placing log10 descriptions. At this moment I have something like:

ticksnofun[xmin_, xmax_] := Module[{i, xmine, xmaxe, xmin10, xmax10},
{xmine, xmaxe} = {xmin, xmax};
{xmin10, xmax10} = (#/Log[10]) & /@ {xmine, xmaxe};
{xmin10, xmax10} = {Ceiling[xmin10], Floor[xmax10]};
tcks10 = Table[i, {i, xmin10, xmax10}];
tckse = (#/Log10[E]) & /@ tcks10;
Transpose[{tckse, Superscript[10, #] & /@ tcks10}]
];


I am curious whether this could be written in a "better" Mathematica way (yet keeping it readable)?

• Definitely looks like a bug. Maybe related to the dynamic magic giving me trouble here.
– Jens
Apr 1, 2016 at 18:03
• Plot doesn't work from either. Apr 1, 2016 at 18:04
• It's not a bug in Plot nor LogLogPlot. Posting answer now. Apr 1, 2016 at 18:05
• You're correct. It is not a bug, per se, in the ticks function, but what is being passed to the ticks function has changed, as I noted in my answer. So, the original ticks function must be modified: LogLogPlot is now passing scaled values, i.e. they are the Log of the range. There is a bug in LogLogPlot in that a ticks function is not accepted at all between 10.0 and 10.3. That has been mostly fixed. Apr 4, 2016 at 17:46
• Natural log, same base, internally, as LogLogPlot. Apr 4, 2016 at 17:56

The advice below is for 10.4 and above. It appears there is a bug in 10.3 and lower.

On the surface, it looks like a bug. But, it is a bug in ticksfun. To see why, we need to see what is being passed into it, so we modify it as follows:

minmax = {};
ticksfun[xmin_, xmax_] := (minmax = {xmin, xmax};
Table[{10^i, Superscript[10, i]},
{i, Floor[Log10[xmin]], Ceiling[Log10[xmax]]}])


Then,

In[30]:= LogLogPlot[Log[x!], {x, 1, 10^5},
PlotRange -> {{0, 10^5}, {10^-1, 10^6}},
Ticks -> {ticksfun, ticksfun}]; minmax

Out[30]= {-2.30259, 13.8155}


So, ticksfun is being passed a negative number which is evaluating to a Complex number, and the Front End is objecting.

Examining the plot range passed to ticksfun shows that LogLogPlot (and family) are now passing the scaled (logarithmic) range to the ticks function. So, the Log10 in ticksfun are now redundant. Also, the range is in base E, so we need to convert to base 10.

Clear[ticksfun2];
ticksfun2[xmin_, xmax_] := Table[
{i Log[10], Superscript[10, i]},
{i, Floor[xmin/Log[10]], Ceiling[xmax/Log[10]]}
]


(Edit: previous versions failed to take the base change into account. Fixed.)

• I'd have used Clip[] myself... Apr 1, 2016 at 18:15
• Hmm. It should be giving the full range. Give me a sec to make adjustments. Apr 1, 2016 at 18:15
• @J.M. I don't think so. Where would I clip it? Apr 1, 2016 at 18:19
• @rcollyer Still doesn't work for me Apr 1, 2016 at 18:20
• @BlacKow there might be a bug there on early versions of 10. What version are you using? Apr 1, 2016 at 18:21