Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can a simple logarithmic number line be drawn between any 2 integer values?

logarithmic number line of integer values

The closest function I found in the documentation is LogLinearPlot[] and I've been racking my brains trying to figure out how to do this with no luck...

share|improve this question

4 Answers 4

up vote 13 down vote accepted

One way is to plot the function 0 against a log axis.

LogLogPlot[0, {t, 1, 12}, Axes -> {True, False}, Ticks -> {Range[12]}]

enter image description here

or, changing the numbers

LogLogPlot[0, {t, 64, 96}, Axes -> {True, False}, Ticks -> {Range[64, 96]}]

enter image description here

The Axis function turns off the vertical axis (because you just want the number line) and the Ticks specifies where you want the tick marks. As a further example (to see the appropriate syntax), here is

 LogLogPlot[0, {t, 1.07, 1.44}, Axes -> {True, False}, 
         Ticks -> {{1.07, 1.15, 1.20, 1.29, 1.38, 1.44}}]

enter image description here

Note the double parentheses in the Ticks list. This is because Ticks is really a list of x-ticks and y-ticks (but since in this case, we aren't plotting any y's, so it is empty).

share|improve this answer
    
What if instead of a range of integers there is a list of irrational numbers? As LogLogPlot generates a plot of 0 as function of t from 1 to 1.5 for example, the number list doesn't seem to fit here. FindDivisions didn't help either so I guess it has to do with setting the ticks according to my defined list. I tried Ticks -> {1.07,1.15,1.20,1.29,1.38,1.44}, also with List but this doesn't work. –  Bo C. Sep 1 '13 at 1:12
    
I added this example, above. Note the double parentheses in the Ticks list. This is because Ticks is really a list of x-ticks and y-ticks (but since in this case, we aren't plotting any y's, it's empty). –  bill s Sep 1 '13 at 1:37

And another way:

logLine[min_, max_] := Module[{lines, labels},

  lines = Line[{{Log[#], -1}, {Log[#], 1}}] & /@ Range[min, max];

  labels = Text[#, {Log[#], 1.7}] & /@ Range[min, max];

  Graphics[{
    labels,
    Line[{{Log[min], 0}, {Log[max], 0}}],
    lines
    }, AspectRatio -> 1/10
   ]

  ]

We have then that logLine[1,12] yields

logline

To plot an arbitrary range we could use the following function:

logLineRange[range_] := Module[{lines, labels},

  lines = Line[{{Log[#], -1}, {Log[#], 1}}] & /@ range;

  labels = Text[#, {Log[#], 1.7}] & /@ range;

  Graphics[{
    labels,
    Line[{{Log[Min[range]], 0}, {Log[Max[range]], 0}}],
    lines
    }, AspectRatio -> 1/10
   ]

  ]

Having defined that function, we can then do this:

logLineRange[{1.07, 1.15, 1.20, 1.29, 1.38, 1.44}]

logline2

share|improve this answer
    
Mathematica can't seem to plot this; tried replacing min and max with 1 and 12, both with and without the _ sign, only in the first line then all over the code - it returns nothing. I'm also interested in a version where the range of integers is replaced with a list of irrational numbers - for example 1.07,1.15,1.20,1.29,1.38,1.44. –  Bo C. Sep 1 '13 at 8:59
    
@Bogdan The code block is just the definition for the function. To actually plot a scale you write logLine[1,12] for example. I added another function which takes an arbitrary range, you can have both those functions defined simultaneously as they take a different number of arguments. I added an example of how to use the second function as well. –  Pickett Sep 1 '13 at 19:05
    
Thank you, everything is clear. How come your first example doesn't work for 1 to 10? Try logLine[1,10] –  Bo C. Sep 2 '13 at 15:45
    
@Bogdan It works for me, don't know why it would not work for you. :/ –  Pickett Sep 2 '13 at 15:49
1  
Very strange, indeed. The Holy Restart solved it. As a side note, your second code can also be used for plotting a specific range with logLineRange[Range[1,12]] –  Bo C. Sep 2 '13 at 17:26

Create unit-sized number lines with tick mapping function f for a list of values vals:

numberLine[f_, vals_List] :=
    With[{pos = Rescale[f /@ vals], tick = 1/50},
        Graphics[{Thick, Line[{{0, 0}, {1, 0}}],
            MapThread[
                {Line[{{#1, -tick}, {#1, tick}}], 
                 Text[#2, {#1, 2 tick}]} &, {pos, vals}]}, 
            PlotRange -> {{-2 tick, 1 + 2 tick}, {3 tick, -tick}}]]

GraphicsColumn[{numberLine[Log, Range[12]], 
    numberLine[Identity, Range[64, 96]]}]

enter image description here

EDIT: Apparently both number lines in the original question are logarithmic, while mine above are logarithmic and linear. This is easy to fix, of course.

share|improve this answer
    
Yes it is. On the last line, replace Identity with Log. I would also like to use your code to plot a version where the range of integers is replaced with a list of irrational numbers - for example 1.07,1.15,1.20,1.29,1.38,1.44. –  Bo C. Sep 1 '13 at 9:04
    
@Bogdan You can replace vals with any list of numeric quantity; for instance, {1, 2, 3, 5, 7, 11, E, Pi, E^2, Pi^2, Sqrt[2], 5 Sin[1], 40/7}. Also, you can use Reals, such as 1.07. There might be some issues with this (solvable by Hold, or multipliers used with tick I believe), but for simpler expressions, it's just fine. –  kirma Sep 1 '13 at 9:16
    
I can't seem to make this work; just replaced vals with the list - only in the first line then again in the second. I'm still searching the documentation to figure out what's wrong. This is the first time i use Mathematica; different versions of the code are my very best tutorial. Thank you. –  Bo C. Sep 1 '13 at 10:13
    
@Bogdan Run Clear[numberLine], re-evaluate above definition of numberLine and try out numberLine[Identity, {1, 2, 3, 5, 7, 11, E, Pi, E^2, Pi^2, Sqrt[2], 5 Sin[1], 40/7}]. Maybe I was a bit vague. For beginners, Range[12], for instance, generates list corresponding to {1, 2, 3, ..., 12}. :) –  kirma Sep 1 '13 at 11:02

Rescale[Log@v](b-a)+a will space any list v of positive values logarithmically over the interval [a,b].

v = Range[12]; Transpose@{N@Rescale[Log@v]*11+1, v}

{1.,      1}
{4.06837, 2}
{5.86326, 3}
{7.13674, 4}
{8.12454, 5}
{8.93163, 6}
{9.61401, 7}
{10.2051, 8}
{10.7265, 9}
{11.1929, 10}
{11.6148, 11}
{12.,     12}

v = Range[64,96,4]; Transpose@{N@Rescale[Log@v]*32+64, v}

{64.,     64}
{68.7846, 68}
{73.2956, 72}
{77.5627, 76}
{81.6109, 80}
{85.4615, 84}
{89.1329, 88}
{92.6411, 92}
{96.,     96}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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