# How to plot intervals and points in the real line?

I need to plot a series of sets of intervals (and points) in the real line. Intervals can be closed, left/right-open or open. (Open/closed ends are marked with empty/filled circles) and isolated points are just dots. Groups of intervals may have a common style and a common legend. Below you can see a mock up.

I can get the basics with the following code

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[title = {Number line}, axis y line=none, y=0.5cm/3, restrict y to domain=0:20, axis lines=left]
\addplot+[only marks] coordinates  {( 3.14, 0 )( 10, 0 )};
\addplot+[only marks] coordinates  {( 20, 0 ) ( 21, 0 )};
\end{axis}
\end{tikzpicture}
\end{document}


but it is difficult to go further, because I couldn't find a way to change the style of the point (e.g. from filled to empty circles) within a coordinates and/or break a single coordinate set to plot two disjoint intervals and points with the same style (like the blue set in the picture).

And alternative that I found is to use tikz draws inside the axis environment

\draw[green, -|] (axis cs:5,0)--(axis cs:6,0); % something like "(-]" or "*-o" (if they worked) may be better


but the points are ignored to set the axis boundaries (which I need to be automatic). Also I need to use pgfplots to keep consistency with other (normal) plots (in terms of the style of the point and lines and the axis).

-

If you use a table instead of coordinates, an empty line tells pgfplots not to connect the points. To change the marker style, you can use the scatter/classes option. Note that this will create one legend entry per scatter class, so in this case, you should only define one.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {Number line},
axis y line=none,
y=0.5cm/3,
restrict y to domain=0:1,
axis lines=left,
enlarge x limits=upper,
scatter/classes={
o={mark=*,fill=white}
},
scatter,
scatter src=explicit symbolic,
every axis plot post/.style={mark=*,thick},
legend style={
draw=none,
at={(1,1)},
anchor=south east
},
legend image post style={mark=none}
]
3.14 c
10 o

13 c
15 c

17 c

Also, legend entries don't work as expected because each break inside table is assigned to a different legend entry and I don't know how to set a forget plot to parts of the table. –  alfC Feb 19 '12 at 9:00