5
$\begingroup$

Mathematica provides a score of convenient functions to make plots with various logarithmic scale axes, for instance I am using ListLogLinearPlot to have a discrete plot with a logarithmic x-axis and a linear y-axis.

My issue however is that I would like the x-axis to be on a binary logarithmic scale, instead of the default logarithmic scale (natural? with decimal ticks?). In particular I need 2, 4, 8, 16, 32, etc. to be equally spaced on the x-axis to highlight the periodic nature of the function I'm plotting.

How may I proceed?

$\endgroup$
5
  • 1
    $\begingroup$ So all you want is defining your custom ticks ? $\endgroup$ Nov 11, 2012 at 17:14
  • $\begingroup$ Yes, I guess :) $\endgroup$
    – Jérémie
    Nov 11, 2012 at 17:45
  • 1
    $\begingroup$ To be clear, all logarithmic scales are just rescalings of each other, because $\log_a x = \ln x/\ln a$. In particular, 2, 4, 8, 16, 32, etc. are already equally spaced in any logarithmic scale: try LogLinearPlot[Cos[x], {x, 1, 16}, AxesOrigin -> {1, 0}, Ticks -> {{1, 2, 4, 8, 16}, Automatic}] and see. $\endgroup$
    – user484
    Nov 11, 2012 at 19:03
  • $\begingroup$ @RahulNarain: Please post this as an answer. $\endgroup$ Nov 11, 2012 at 23:58
  • $\begingroup$ @Brett: Done.${}$ $\endgroup$
    – user484
    Nov 12, 2012 at 4:02

2 Answers 2

4
$\begingroup$

You can use the normal ListPlot and scale/label your data :

data = Table[{Log[x]/Log[2], Cos[x]}, {x, Range[1, 16, 0.05]}];

myTicks = {Log[#]/Log[2], #} & /@ Range[1, 16];

ListPlot[data, Ticks -> {myTicks, Automatic}]

plot

$\endgroup$
0
9
$\begingroup$

By request:

You don't need a new kind of plot function for this. The existing logarithmic plots already do exactly what you want! It doesn't matter what the base of the logarithm is: all logarithmic scales are just rescalings of each other, because $$\log_a x = \frac{\ln x}{\ln a}$$ for any base $a$. In particular, 2, 4, 8, 16, 32, etc. are already equally spaced in any logarithmic scale. For example:

LogLinearPlot[Cos[x], {x, 1, 16}, AxesOrigin -> {1, 0}, Ticks -> {{1, 2, 4, 8, 16}, Automatic}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.