# How to draw/fill half-open intervals on a ray of numbers? (tikz; incl. minimal ex.)

I would like to indicate intervals on a ray of numbers. Here is an example including a half-open interval (I would like to draw another one from c to 1-b). I am sure my method to achieve this can be improved... (especially since it is not really exact -- I draw a filled rectangle but the interval is open to the right). What's a better way to achieve this?

\documentclass{scrartcl}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[mydrawstyle/.style={draw=black, very thick}, x=1mm, y=1mm, z=1mm]
\draw[mydrawstyle, ->](-2,30)--(66,30) node at (-6,30)[left]{$x=1$};
\draw[mydrawstyle](0,28)--(0,32) node[below=10]{$0$};
\draw[mydrawstyle](10,28)--(10,32) node[above=4]{$c$};
\draw[mydrawstyle](25,28)--(25,32) node[below=10]{$1-b$};
\draw[mydrawstyle](50,28)--(50,32) node[below=10]{$1-a$};
\draw[mydrawstyle](60,28)--(60,32) node[below=10]{$1$};
\fill[fill=blue, opacity=0.2](0,29)--(0,31)--(10,31)--(10,29)--(0,29);
\draw[mydrawstyle, draw=blue](1,29)--(0,29)--(0,31)--(1,31);
\draw[mydrawstyle, draw=blue](10,30) arc (0:45:1.8);
\draw[mydrawstyle, draw=blue](10,30) arc (0:-45:1.8);
\end{tikzpicture}
\end{document}


Output:

-
Does this help? Could be easily modified to make half-open intervals, which are often drawn with open circles instead of filled in circles. tex.stackexchange.com/questions/45006/… – Chris Chudzicki Nov 12 '13 at 0:51
... it was one of the links suggested before I submitted the question... but I don't like it too much. I would rather be interested how one can draw the interval with '[' and ')', and with it being filled. I would guess one would draw a filled rectangle with the corners on the right being rounded but then kind of clip before drawing the boundary... but, well, I am not sure. – Marius Hofert Nov 12 '13 at 0:53
– Qrrbrbirlbel Nov 12 '13 at 1:57

I would like to do this using the [- and -) arrow stylings. This is very easy without the translucency. The approach to translucency can probably be improved.

I changed the coordinates a bit, I hope this isn't too annoying.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

%Without Transparency:
\begin{tikzpicture}[scale=7]
\draw[->, thick] (-0.1,0) -- (1.1,0);
\foreach \x/\xtext in {0/0,0.2/,0.4/$1-b$,0.8/$1-a$,1}
\draw[thick] (\x,0.5pt) -- (\x,-0.5pt) node[below] {\xtext};
\draw (0.2,0.5pt) node[above] {$c$};
\draw[[-), ultra thick, blue] (0,0) -- (0.2,0);
\draw (-0.25,0) node {$x=1$};
\end{tikzpicture}

%With Transparency
\begin{tikzpicture}[scale=7]
\draw[->, thick] (-0.1,0) -- (1.1,0);
\foreach \x/\xtext in {0/0,0.2/,0.4/$1-b$,0.8/$1-a$,1}
\draw[thick] (\x,0.5pt) -- (\x,-0.5pt) node[below] {\xtext};
\draw (0.2,0.5pt) node[above] {$c$};
\draw[[-, ultra thick, blue] (0,0) -- (0.01,0);
\draw[-), ultra thick, blue] (0.19,0) -- (0.2,0);
\fill[opacity = 0.2, blue,rounded corners=1ex] (0,-.16ex) -- (0.2, -.16ex) -- (0.2, .16ex) -- (0,.16ex) -- cycle;
\draw (-0.25,0) node {$x=1$};
\end{tikzpicture}

\end{document}


Edit: Added rounded corners as suggested by Harish Kumar.

-
Or \fill[opacity = 0.2, blue,rounded corners=1ex] (0,-.16ex) -- (0.2, -.16ex) -- (0.2, .16ex) -- (0,.16ex) -- cycle; – Harish Kumar Nov 12 '13 at 2:03
@HarishKumar Great suggestion! – Chris Chudzicki Nov 12 '13 at 2:46
Hi, this looks awesome (especially when combining the two approaches). I ran into another problem: If you replace [-) by [-], the closing bracket causes the error Package tikz Error: Giving up on this path. Did you forget a semicolon?. How would you draw a [-] arrow/interval then? I tried to escape the closing brackets in various ways, but didn't succeed – Marius Hofert Nov 12 '13 at 8:00
Got it, {[-]} works :-) – Marius Hofert Nov 12 '13 at 8:04