How can a simple logarithmic number line be drawn between any 2 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...
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow can a simple logarithmic number line be drawn between any 2 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...
One way is to plot the function 0
against a log axis.
LogLogPlot[0, {t, 1, 12}, Axes -> {True, False}, Ticks -> {Range[12]}]
or, changing the numbers
LogLogPlot[0, {t, 64, 96}, Axes -> {True, False}, Ticks -> {Range[64, 96]}]
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}}]
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).
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.
$\endgroup$
– Bo C.
Sep 1 '13 at 1:12
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).
$\endgroup$
– 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
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}]
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
.
$\endgroup$
– Bo C.
Sep 1 '13 at 8:59
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.
$\endgroup$
– C. E.
Sep 1 '13 at 19:05
logLine[1,10]
$\endgroup$
– Bo C.
Sep 2 '13 at 15:45
logLineRange[Range[1,12]]
$\endgroup$
– 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]]}]
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.
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
.
$\endgroup$
– Bo C.
Sep 1 '13 at 9:04
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.
$\endgroup$
– kirma
Sep 1 '13 at 9:16
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.
$\endgroup$
– Bo C.
Sep 1 '13 at 10:13
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}
. :)
$\endgroup$
– 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}