# X-Bar plot with intervall (a,b) rather than (0,a)

When one makes a xbar plot using pgfplots, the bar always goes from 0 to the requested coordinate. For example (p. 78 in pgfplots manual):

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
width=12cm, height=3.5cm, enlarge y limits=0.5,
symbolic y coords={no,yes},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
\addplot coordinates {(3,no) (7,yes)};
\end{axis}
\end{tikzpicture}
\end{document}


However, I'd like the bars to be at different intervals, say no: 1 to 3, yes: 2 to 7. I didn't find anything in the manual that I could immediately apply to my problem.

## 1 Answer

You can use stacked plots for this, with the first series made invisible using draw=none, forget plot:

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\begin{document}

\pgfplotstableread{
Lower Upper Name
1 3 no
2 7 yes
}\loadedtable

\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
width=12cm, height=3.5cm, enlarge y limits=0.5,
symbolic y coords={no,yes},
ytick=data,xbar stacked,
bar shift=0pt
]

\addplot [draw=none, forget plot] table [x=Lower, y=Name]{\loadedtable};
\addplot table [x expr=\thisrow{Upper}-\thisrow{Lower}, y=Name]{\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}