4
$\begingroup$

I have a piecewise function that is defined in logarithmic intervals, i.e., the different pieces are defined on

{{1. <= x <= 10}, {10 <= x <= 100}, {100 <= x <= 1000}}

I'd like to visualize the different domains on a number line. NumberLinePlot, of course, works, but it looks clumsy as the plot is fully dominated by the last domain an the first one is barely visible:

NumberLinePlot[{{1. <= x <= 10}, {10 <= x <= 100}, {100 <= x <= 1000}}, {x, 1, 1000}]

enter image description here

So I can use something along the lines of

NumberLinePlot[
  {{Log[10, 1] <= x <= Log[10, 10]}, 
   {Log[10, 10] <= x <= Log[10, 100]}, 
   {Log[10, 100] <= x <= Log[10, 1000]}}, 
  {x, Log[10, 1], Log[10, 1000]}]

which results in a much more pleasantly balanced plot:

enter image description here

However, now the number line ticks show the exponents — so in essence I'd like something like NumberLineLogPlot, but that doesn't exist.

I tried to recreate something like that by abusing LogLogPlot

Show[
  MapThread[
    LogLogPlot[#1, #2, PlotStyle -> #3] &, 
    {{1, 2, 4}, {x, #[[1, 1]], #[[1, 3]]} & /@ dx , {Red, Green, Blue}}], 
  PlotRange -> Automatic, Frame -> {{False, False}, {True, False}}]

Which leads to something like

enter image description here

which is better in terms of the logarithmic x-axis but is quite clumsy in other ways.

Any ideas how to implement a NumberLineLogPlot nicely?

$\endgroup$
4
$\begingroup$

Use the option Ticks

intervals = {{1 <= x <= 10}, {10 <= x <= 100}, {100 <= x <= 1000}};

logIntervals = intervals /. {n_?NumericQ :> Log10[n]}

(* {{0 <= x <= 1}, {1 <= x <= 2}, {2 <= x <= 3}} *)

NumberLinePlot[logIntervals, {x, 0, 3}, 
 Ticks -> {({Log10[#], #} & /@ 
    {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000}), None}]

enter image description here

$\endgroup$
  • $\begingroup$ Nice one! I particularly like the trick with the patternreplacement for the Log[] $\endgroup$ – Oliver Jennrich Feb 3 '19 at 15:32
0
$\begingroup$

You can also transform intervals into a list of lists and use ListLinePlot with the option ScalingFunctions:

lst = MapIndexed[Thread[{#[[1]], #2[[1]]/2}] &, intervals /. LessEqual -> ({#, #3} &)]; 
Show[ListLinePlot[lst, ScalingFunctions -> {{Log[10, #] &, 10^# &}, None},
   Joined -> #] & /@ {True, False}, AspectRatio -> 1/5, Axes -> {True, False}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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