# How does the undocumented option ScalingFunctions work with Plot versus ListPlot?

Say that I want to reverse the x-axis of a plot, there are a few solutions on here (like those in the answers here and here) but most of them are valid only for a ListPlot variant and not a Plot variant.

The answer by MarcoB in the second link above uses the option ScalingFunctions to achieve the goal and I was interested in how to apply it to a Plot (or LogPlot or LogLogPlot, etc). It seems to work just fine in reversing the x-axis if the function being plotted is linear:

{Plot[2 (k - 2), {k, -5, 0}, PlotRange -> All],
Plot[2 (k - 2), {k, -5, 0},
ScalingFunctions -> {{-# &, -# &}, Identity}, PlotRange -> All]} but it gives strange results when the function is nonlinear,

{Plot[2 (k - 2)^3, {k, -5, 0}, PlotRange -> All],
Plot[2 (k - 2)^3, {k, -5, 0},
ScalingFunctions -> {{-# &, -# &}, Identity}, PlotRange -> All]} If I try the same thing on a ListPlot it works just fine,

list = {#, 2 (# - 2)^3} & /@ Range[-5, 0, .1];
{ListPlot[list, PlotRange -> All],
ListPlot[list, ScalingFunctions -> {{-# &, -# &}, Identity},
PlotRange -> All]} Is there a way to do this with ScalingFunctions, or is it simply not supported and I need to use my own workaround?

• Even simpler problematic case: Plot[0, {t, 0, 1}, ScalingFunctions -> {Identity, "Log"}] puts the line at y == 1 when there should be no line. – István Zachar Mar 17 '16 at 11:00

Examination of the two nonlinear Plots (from the second piece of code in the question) with InputForm shows that ScalingFunctions correctly modifies the Ticks option but retains only the first and last elements of Line . Based on this observation, a fairly simple work-around is

(Edit: code simplified)

Plot[2 (k - 2)^3, {k, -5, 0}, PlotRange -> All] /.
{Line[z_] :> Line[MapAt[-# &, z, {All, 1}]],
Rule[Ticks, {_, z_}] -> Rule[Ticks, {ChartingScaledTicks[{-#1 &, -#1 &}], z}]} ScalingFunctions works fine with ParametricPlot, although apparently not with Plot. Thus,
ParametricPlot[{k, 2 (k - 2)^3}, {k, -5, 0}, ScalingFunctions -> {{-# &, -# &}, Identity},

also produces the plot above. This update is based on Mr. Wizard's answer to question 13253. Incidentally, "Reverse" has the same effect as {-# &, -# &}.
• I particularly like the idea of using ParametricPlot as a stand-in for Plot when rescaling is needed, since it enjoys similar adaptive sampling etc. Very clever workaround! (+1) – MarcoB Feb 16 '16 at 0:07
• I agree, brilliant to use ParametricPlot! Especially since I am continually confunded by ChartingScaledTicks, and always resort to CustomTicks instead. – Jason B. Feb 16 '16 at 9:17
• @JasonB Thank you for your acceptance and kind words. Do you feel that the behavior of ChartingScaledTicks in Plot is a bug? Although it is not documented, this option is recognized by Plot and produces an incorrect answer. Also, according to the documentation of Plot and ParametricPlot`, the former is a special case of the latter. – bbgodfrey Feb 16 '16 at 12:32