# Shift y labels, stop y labels being dropped

I have a const plot with intervals on the y-axis. I'd like my y labels to be centered in each bar, as it would be if this were an xbar interval graph.

Also, and more importantly, I'd like more flexibility and control in the y label intervals. Can I, for instance, include every other interval, as in [0,.05) [.1,.15) etc., with that gap in between?

Finally, is there an easy way to make the last interval a closed bracket on both sides?

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
height=10cm,
const plot,
y tick label as interval=true,
ytick=,
yticklabel={$[\pgfmathprintnumber\tick, \pgfmathprintnumber\nexttick)$},
enlargelimits=false,
ymin=0,
xmin=0
]
coordinates
{(0,0) (393,0.000) (93,0.050) (44,0.100) (49,0.150) (31,0.200) (32,0.250) (37,0.300) (52,0.350) (90,0.400) (30,0.450) (26,0.500) (11,0.550) (32,0.600) (31,0.650) (15,0.700) (33,0.750) (18,0.800) (25,0.850) (31,0.900) (162,0.950) (0,1)};
\end{axis}
\end{tikzpicture}

\end{document}

-
I should say that I'm not using xbar interval because I'm adding another plot, and I prefer no gaps between bars for both plots. –  PaulB Feb 4 '13 at 21:20
If you want to add something to your question as you do in the comment above, you can just edit your question to add it there. This is better than adding such things in the comments as they are less likely to be read. –  Benedikt Bauer Feb 4 '13 at 21:25
I think that just about does it percuße, but I'll have to also shift my coordinates as that gives me from [0,.05) to [.9,.95) –  PaulB Feb 4 '13 at 21:29

To get one label for each bar, you can set ytick=data. To get the closed interval, you can use an inline check to see if the upper bound of the bin is 1, using \ifdim\nexttick pt=1pt ] \else ) \fi (\ifdim needs the values it compares to have units, that's why we'll use pt). To make sure everything aligns nicely, you should use \pgfmathprintnumber[fixed, fixed zerofill]{...}, and print the square bracket using \leavevmode\rlap{]}\hphantom{)} (as egreg kindly told me).

To print only some labels, ordinarily you'd use ytick={0,0.1,...,1}, but in the case of interval ticks that doesn't do what you want it to (it would plot 0-0.1, 0.1-0.2, while you want 0-0.05,0.1-0.15), so we'll have to do something else: We can introduce a counter that is incremented for every tick, and at each tick we check whether the counter value is divisible by 2 (or 3 or whatever) using \pgfmathparse. If it is, we print the tick label, if it isn't we don't:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\newcounter{ticknumber}
\setcounter{ticknumber}{1}
\makeatletter
\begin{tikzpicture}
\begin{axis}[
height=10cm,
const plot,
y tick label as interval=true,
ytick=data,
yticklabel={%
\pgfmathtruncatemacro\isdivisible{Mod(\theticknumber,2)==0}
\ifnum\isdivisible=1
$[\pgfmathprintnumber[fixed, fixed zerofill]\tick, \pgfmathprintnumber[fixed, fixed zerofill]\nexttick\ifdim\nexttick pt=1pt \leavevmode\rlap{]}\hphantom{)} \else ) \fi$
\fi
\stepcounter{ticknumber}
},
enlargelimits=false,
ymin=0,
xmin=0
]