2
$\begingroup$

I want to display a value on a fixed range say [0,2].

NumberLinePlot[.2, {x, 0, 2}]

result

NumberLinePlot[1.9, {x, 0, 2}]

result

Mathematica tries to guess the best range to display, so it zooms in on [0,1] for the small value and zooms out to [0,4] for the large one, which is natural.

To freeze the range displayed, I tried adding various option even though they are not listed as a possible option in the documentation. The result is ... unexpected as PlotRange shrinks to [0,1], PlotRegion zooms out to [0,4] and RegionFunction is not accepted:

NumberLinePlot[1.9, {x, 0, 2}, PlotRange -> {0, 2}]

result

NumberLinePlot[1.9, {x, 0, 2}, PlotRegion -> {0, 2}]

enter image description here

Any idea on how to impose the range to [0,2] ? My ultimate goal is to make a dynamic slider but with a range that does not jumps around when x changes which is currently the case if I try :

Manipulate[NumberLinePlot[x], {x, 0, 2}]

Thanks.

PS. I am using Mathematica 11.3 on MacOS 10.13.4.

$\endgroup$
2
  • 1
    $\begingroup$ does Show[NumberLinePlot[1.9, {x, 0, 2}], PlotRange->{{0,2},All}] work? $\endgroup$ Commented May 18, 2018 at 11:56
  • $\begingroup$ Thanks everyone for trying. It seems that on v11.3 the only way to answer my question is to pass the PlotRange option to Show as in @kglr answer below. I will validate this one but I am glad to know they might fix the bug in the next version. $\endgroup$ Commented May 20, 2018 at 11:22

4 Answers 4

1
$\begingroup$
Show[NumberLinePlot[1.9, {x, 0, 2}], PlotRange -> {{0, 2}, All}]

enter image description here

$Version

"11.3.0 for Linux x86 (64-bit) (March 7, 2018)"

Also works with v11.3 on a Mac (thanks: @Bob Hanlon).

$\endgroup$
0
1
$\begingroup$

You need to state that {0, 2} refers to the x-range. By default, listing one range refers to the y-range.

NumberLinePlot[1.9, {x, 0, 2}, PlotRange -> {{0, 2}, Automatic}]

enter image description here


Edit

This method does not work in 11.3, but works in older versions and appears to be fixed for the next version already.

$\endgroup$
2
  • 2
    $\begingroup$ With v11 .3 on a Mac, with this code the number line shown is the interval {0, 1} and the point is not shown (it is outside the displayed interval). $\endgroup$ Commented May 18, 2018 at 14:49
  • $\begingroup$ Oh interesting. This seems to only be an issue for 11.3. I just tried 11.1, 11.2, and the current 12.0 prototype and they all work correctly. $\endgroup$ Commented May 18, 2018 at 14:52
0
$\begingroup$

Try this:

Manipulate[
 NumberLinePlot[x, PlotRange -> {0, 2}, PlotStyle -> Blue], {x, 0, 2}]

enter image description here

Have fun!

$\endgroup$
1
  • 1
    $\begingroup$ With v11.3 on a Mac, for this code the number line is fixed on the interval {0, 1} and the right half of the Manipulate control does not display the point. $\endgroup$ Commented May 18, 2018 at 14:44
0
$\begingroup$

Just another way:

$Version
(*"11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"*)

NumberLinePlot[x == 0.2, {x, 0, 2}, PlotRange -> {{0, 2}, {0, 0}}]

NumberLinePlot[x == 0.2, {x, 0, 2}, PlotRange -> {0, 2}]

NumberLinePlot[x == 0.2, {x, 0, 2}, PlotRange -> Full]

NumberLinePlot[x == 0.2, {x, 0, 2}, PlotRange -> All]

Manipulate[NumberLinePlot[y == x, {y, 0, 2}, PlotStyle -> Blue], {x, 0, 2}]
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.