I would like to plot a simple interval on the number line in Mathematica. How do I do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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]]andSortto 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 givenexprreduces toTrueorFalse, my code does not die gracefully.(Note: I had originally tried to use
ArrowandArrowheadsto draw the lines – but sinceArrowheadsautomatically rescales the arrow heads with respect to the width of the encompassing graphics, it gave me too many headaches.)OK, some examples:
Edit: Let’s compare the above to the output of Wolfram|Alpha
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
WolframAlphais not quite a normalGraphicsobject, so it’s hard to modify itsOptionsor combine usingShow. To see the various numberline objects that Wolfram|Alpha can return, runWolframAlpha["x>0", {{"NumberLine"}}]– “Content”, “Cell” and “Input” all return basically the same object. Anyway, to get a graphics object fromyou can, for example, run
Then we can modify the graphics objects and combine them in a grid to get