# Manipulating the axis on a ListLinePlot

I am trying to create a plot using ListLinePlot in which the x-axis is represented in a logarithmic scale, and is reversed (so larger values are on the right side).

I have found that ScalingFunctions -> {"Reverse"} will reverse the axis and ScalingFunctions -> {"Log"} will scale the axis to a log scale, but the two commands will not work together.

Does anyone have any ideas?

• In Mathematica 8, ScalingFunctions is not an option for ListLinePlot. Are you using a different version of Mathematica? Sep 6, 2012 at 4:13
• @CarlMorris actually, they are not documented to do so, but they do (see also here). Sep 6, 2012 at 4:25
• @Verbeia It seems "Reverse" does not work for ListLogLinearPlot Sep 6, 2012 at 4:53
• @Verde I know, but I got tangled in my answer and hadn't posted it until now. Sep 6, 2012 at 5:19

If you want to stick with ScalingFunctions then you just have to use a pure function where you specify the transformation you would like to have. Simple example:

ListLinePlot[Table[{x, x^2 + 10}, {x, 0, 10, 1}],
ScalingFunctions -> {None, {Sqrt[# - 10] &, #^2 + 10 &}}
]


So what you have to do is to supply a function for the x-axis which reverses and takes the log and you need to supply the inverse transformation for that.

• Take a look at this : #[Table[{n, Sqrt[n]}, {n, 1000}], ScalingFunctions -> {{-Log@# &, E^-# &}, None}] & /@ {ListPlot, ListLinePlot} Sep 6, 2012 at 11:42
tick = AbsoluteOptions[ListLogLinearPlot[Table[{n, Sqrt[n]}, {n, 1000}]], Ticks][[1,2]];
t1 = {tick[] /. {x_, y_, z_, w_} -> {-x, y, z, w}, tick[]};
ListPlot[Table[{-Log@n, Sqrt[n]}, {n, 1000}], Ticks -> t1] (The usual credit to @Heike for her torn[] function)

There doesn't seem to be a way you can get both log and reversed x-axes out of the box.

Consider some data that might warrant such a presentation:

data = Sort@RandomVariate[LogNormalDistribution[0.2, 2.], {40, 2}];


ListLogLinearPlot gives a log x-axis and normal y-axis

ListLogLinearPlot[data, Joined -> True, PlotRange -> All] The ScalingFunction option isn't meant to work for ListLinePlot, but it actually does.

ListLinePlot[data, Joined -> True,
ScalingFunctions -> {"Reverse", None}] However, it doesn't work for ListLogLinearPlot.

So, the answer is to manipulate data and ticks much in the same way as Verde's answer suggests.

You can write a custom tick function that takes the maximum and minimum data points and builds tick functions from that. I am not going to pretend this is quite the function you want (I got tangled and don't have time to fix it now), but you can see how to build a general tick function that doesn't require specific knowledge of the data upfront.

 loggedticks[min_, max_] :=
Table[{i, ScientificForm[10^i]}, {i, Floor@Log[10, min],Ceiling@Log[10, max]}]

ListLogLinearPlot[data, Joined -> True,
Ticks -> {loggedticks, Automatic}]

• There is a way to get both things with ScalingFunctions. See halirutan's answer and my comment below. Really unexpected. Sep 6, 2012 at 11:46