Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:57:15+00:00 2026-05-24T00:57:15+00:00

I would like to plot a simple interval on the number line in Mathematica.

  • 0

I would like to plot a simple interval on the number line in Mathematica. How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:57:16+00:00Added an answer on May 24, 2026 at 12:57 am

    Here’s another attempt that draws number lines with the more conventional white and black circles, although any graphics element that you want can be easily swapped out.

    It relies on LogicalExpand[Simplify@Reduce[expr, x]] and Sort to get the expression into something resembling a canonical form that the replacement rules can work on. This is not extensively tested and probably a little fragile. For example if the given expr reduces to True or False, my code does not die gracefully.

    numLine[expr_, x_Symbol:x, range:{_, _}:{Null, Null}, 
      Optional[hs:_?NumericQ, 1/30], opts:OptionsPattern[]] := 
     Module[{le = {LogicalExpand[Simplify@Reduce[expr, x]]} /. Or -> List,
       max, min, len, ints = {}, h, disk, hArrow, lt = Less|LessEqual, gt = Greater|GreaterEqual},
      If[TrueQ@MatchQ[range, {a_, b_} /; a < b],
       {min, max} = range,
       {min, max} = Through[{Min, Max}@Cases[le, _?NumericQ, \[Infinity]]]];
      len =Max[{max - min, 1}]; h = len hs;
      hArrow[{x1_, x2_}, head1_, head2_] := {{Thick, Line[{{x1, h}, {x2, h}}]},
                                             Tooltip[head1, x1], Tooltip[head2, x2]};
      disk[a_, ltgt_] := {EdgeForm[{Thick, Black}], 
        Switch[ltgt, Less | Greater, White, LessEqual | GreaterEqual, Black], 
        Disk[{a, h}, h]};
      With[{p = Position[le, And[_, _]]}, 
           ints = Extract[le, p] /. And -> (SortBy[And[##], First] &); 
           le = Delete[le, p]];   
      ints = ints /. (l1 : lt)[a_, x] && (l2 : lt)[x, b_] :> 
         hArrow[{a, b}, disk[a, l1], disk[b, l2]];
      le = le /. {(*_Unequal|True|False:>Null,*)
         (l : lt)[x, a_] :> (min = min - .3 len; 
           hArrow[{a, min}, disk[a, l], 
            Polygon[{{min, 0}, {min, 2 h}, {min - Sqrt[3] h, h}}]]),
         (g : gt)[x, a_] :> (max = max + .3 len; 
           hArrow[{a, max}, disk[a, g], 
            Polygon[{{max, 0}, {max, 2 h}, {max + Sqrt[3] h, h}}]])};
      Graphics[{ints, le}, opts, Axes -> {True, False}, 
       PlotRange -> {{min - .1 len, max + .1 len}, {-h, 3 h}},
       GridLines -> Dynamic[{{#, Gray}} & /@ MousePosition[
                               {"Graphics", Graphics}, None]], 
       Method -> {"GridLinesInFront" -> True}]
      ]
    

    (Note: I had originally tried to use Arrow and Arrowheads to draw the lines – but since Arrowheads automatically rescales the arrow heads with respect to the width of the encompassing graphics, it gave me too many headaches.)

    OK, some examples:

    numLine[0 < x], 
    numLine[0 > x]
    numLine[0 < x <= 1, ImageSize -> Medium]
    

    enter image description here
    enter image description here
    enter image description here

    numLine[0 < x <= 1 || x > 2, Ticks -> {{0, 1, 2}}]
    

    enter image description here

    numLine[x <= 1 && x != 0, Ticks -> {{0, 1}}]
    

    enter image description here

    GraphicsColumn[{
      numLine[0 < x <= 1 || x >= 2 || x < 0],
      numLine[0 < x <= 1 || x >= 2 || x <= 0, x, {0, 2}]
      }]
    

    enter image description here

    Edit: Let’s compare the above to the output of Wolfram|Alpha

    WolframAlpha["0 < x <= 1 or x >= 2 or x < 0", {{"NumberLine", 1}, "Content"}]
    WolframAlpha["0 < x <= 1 or x >= 2 or x <= 0", {{"NumberLine", 1}, "Content"}]
    

    output of the above

    Note (when viewing the above in a Mathematica session or the W|A website) the fancy tooltips on the important points and the gray, dynamic grid lines. I’ve stolen these ideas and incorporated them into the edited numLine[] code above.

    The output from WolframAlpha is not quite a normal Graphics object, so it’s hard to modify its Options or combine using Show. To see the various numberline objects that Wolfram|Alpha can return, run WolframAlpha["x>0", {{"NumberLine"}}] – “Content”, “Cell” and “Input” all return basically the same object. Anyway, to get a graphics object from

    wa = WolframAlpha["x>0", {{"NumberLine", 1}, "Content"}]
    

    you can, for example, run

    Graphics@@First@Cases[wa, GraphicsBox[__], Infinity, 1]
    

    Then we can modify the graphics objects and combine them in a grid to get

    aligned

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to plot a vertical line (I'd prefer any orientation, but I'd
I have a very simple problem regarding plot settings. I would like to have
I would like to plot a simple graphic. I have a dat set with
I plot a simple linear regression using R. I would like to save that
I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg.
I would like to plot y1 and y2 in the same plot. x <-
I would like to create a simple flow chart in latex with the TikZ
I would like to put an int into a string . This is what
I've created a simple scatter plot in R with specific RGB color values like
I have a dataset with labels which I would like to plot with points

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.