How to graph a number line with an interval or ray shown on it?

In Wolfram Mathematica there is a function called NumberLinePlot that plots data on nuber line like an interval (closed or open) or rays. I am wonder if there is such a plot function in Matlab? (see example from Wolfram Mathematica bellow in the attached picture). What would be the code to create such a graph in Matlab.

Answers (1)

Nothing like that exists in MATLAB handle graphics and nothing can be drawn in MATLAB other than into a figure axes, so it's unlikely you'll find this of any real value, but one can klunk something sorta' similar together excepting it will still be tied to the figure...
hAx=axes;
pos=hAx.Position;
pos(4)=0.05;
hAx.Position=pos;
hAx.YAxis.Visible='off';
hAx.XAxis.TickLength=0* hAx.XAxis.TickLength;
box off
xlim([-1.1 0.15])
hAx.XAxis.TickLabelFormat='%0.1f';
hA=annotation('textarrow',[0.5 0.9],0.15*[1 1]);
%hL=plot([0 0],[nan nan],'k-'); % this didn't work
%hLg=legend(hL,'X > -1/2','Location','eastoutside');
Other stuff would have to be added with text or other annotation.
The end result is you can draw something that looks similar, but not sure it would be of any use having done so...

2 Comments

Thanks dpb, that all I need to know that there is no a dedicated function to do this. And yes, this long code is not useful if you want a quick tool to visualize intervals or rays for educational porpose.
"... this long code is not useful if you want a quick tool "
The "trick" is to build the needed functionality once in an m-file that can then be called in one line.
The Q? is just what one really wants to be able to do with the tool...

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2025b

Asked:

on 12 Jan 2026

Edited:

dpb
on 12 Jan 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!