# ScalingFunctions - reversing a logarithmic axes

I have been playing with ScalingFunctions in Mathematica 11.0. I wanted to produce a logarithmic scaled plot with the direction reversed. I have had success with accomplishing my goals, but I have no understanding of why it works.

I am able to reverse the axis and/or create a logarithmic axes with out a problem.

Plot[x, {x, 1, 3},
PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> "Reverse"
] Plot[x, {x, 1, 3},
PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> "Log"
] In the documentation it talks about using as a scaling function and gives an example of

{-Log[#] &, Exp[-#] &}


I decided to try it.

Plot[x, {x, 1, 3},
PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> {None, {-Log[#] &, Exp[-#] &}}
] It produced what I wanted and in one sense that makes this a success. However, I am completely confused by what is going on.

The question is why does supplying ScalingFunctions with the negative of a the log and its inverse produce a logarithmic scaled plot with the direction reversed?

I've been curious about what the two different functions do in ScalingFunctions. I think we can get a clue by these two plots

Plot[x, {x, 1, 3}, PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> {None, #}] & /@ {{# &,
Exp[-#] &}, {-Log[#] &, # &}} So the first function is applied to the points, and the second function somehow used to construct the tick marks.

{regularPlot = Plot[x, {x, 1, 3}, PlotRange -> {{1, 3}, {1, 3}}],
reverseLogPlot =
Plot[x, {x, 1, 3}, PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> {None, {-Log[#] &, Exp[-#] &}}]}


We can extract the plotted points from the first, apply -Log[#]& to them, and compare that to the points from the scaled plot,

list = Cases[regularPlot, Line[x__] :> x, Infinity] //
First; reverseLogList =
reverseLogPlot // Cases[#, Line[x__] :> x, Infinity] & // First;
ListPlot /@ {reverseLogList, {#1, -Log[#2]} & @@@ list} and this confirms our suspicions about the first function.

I'm not sure exactly how the second function is applied to the tick marks though. This isn't quite right:

ListLinePlot[{#1, -Log[#2]} & @@@ list,
Ticks -> {Automatic, {#, NumberForm[Exp[-#], 2]} & /@
Range[-1, 0, .1]}] ## Edit

Actually, I have no idea how these functions seem to work, why do these simple examples do nothing?

Plot[x, {x, -1, 3}, PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> {None, {# + 2 &, # - 2 &}}]
Plot[x, {x, -1, 3}, PlotRange -> {{1, 3}, {1, 3}},
ScalingFunctions -> {None, {2 # &, #/2 &}}] And why does removing the PlotRange option make the first one almost work, but the second one fails mysteriously?

Plot[x, {x, -1, 3}, ScalingFunctions -> {None, {# + 2 &, # - 2 &}}]
Plot[x, {x, -1, 3}, ScalingFunctions -> {None, {2 # &, #/2 &}}] • This is helpful, but I am still confused by the interface. If the scaling function is monotone, the user should not need to provide the inverse. Is there a clear use case where being able to provide both arguments is desirable? – Alan Sep 14 '16 at 13:47
• @Alan - actually, now that I look further, I have no idea what these functions do, and I might just delete this answer - why do scaling functions like {2 # &, #/2 &} and {2 + # &, #-2 &} not work at all? To answer your question - it would be useful to be able to independently scale the plot and its tick marks. – Jason B. Sep 14 '16 at 13:55
• @JasonB I am convinced you are on the right track. As you pointed out the y values in reverseLogPlot are the log of the data. Applying Cases[reverseLogPlot, Rule[Ticks, x_List] -> x, Infinity] results in {{Automatic, ChartingScaledTicks[{-Log[#1] &, Exp[-#1] &}]. It needs to apply the inverse in order to get the ticks to come out right. It apparently uses some sophistication as it uses a package function ChartingScaledTicks. – Jack LaVigne Sep 14 '16 at 14:55
• @JackLaVigne - I remember trying to figure out ScaledTicks as well, and giving up. I wanted, just like here, to start at the simplest example: {2#, #/2} or {# +2, # -2}. And they failed there also – Jason B. Sep 14 '16 at 15:53
• Your guess for the usage of the last syntax of ScalingFunctions is correct, and your last 4 examples have worked as expected actually. Try Plot[x, {x, -1, 3}, PlotRange -> {{1, 3}, {1, 3}}, ScalingFunctions -> {None, {2 # &, #/2 &}}, AspectRatio -> Automatic] and you'll know what I mean. – xzczd Jun 27 '18 at 13:41