# Legend problem with horizontal bars in pgfplots

I have a problem with a weird offset with horizontal bars in a pgfplots legend. They seem to be moved "up" a bit, so a part of them is hidden under overflow. An image of the situation which explains it quicker:

Minimal TeX to reproduce (I am compiling with pdflatex):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
enlargelimits=0.25,
legend style={},
symbolic y coords={A,B,C},
ytick=data,
y tick label style={rotate=90},
]
\legend{legend1, legend2, legend3}
\end{axis}
\end{tikzpicture}
\end{document}


Q: How do I get the correct image of the horizontal bars? Expected output for me is to have the two vertical bars just like in other bar-style legends from pgfplots, e.g. in the question here: Reason for multiple bars in Legend entries

Q: or is it correct this way? If so, is it possible to modify the "thumbnail" to show something else?

Update

With the new pgfplots version 1.13 the code of the OP works as expected:

So if you can use version 1.13 the workaround in the answer below is not needed anymore.

Original answer (used with version 1.12):

As you can see in the documentation or in the pgfplots.code.tex the xbar legend image is defined by

/pgfplots/xbar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em)(2*\pgfplotbarwidth,0.6em)};}
}


But I think the x and y coordinates should be interchanged:

/pgfplots/xbar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0.8em,0cm)(0.6em,2*\pgfplotbarwidth)};}% <- changed
}


Code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{
/pgfplots/xbar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0.8em,0cm)(0.6em,2*\pgfplotbarwidth)};}% <- changed
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
enlargelimits=0.25,
%legend style={},
symbolic y coords={A,B,C},
ytick=data,
y tick label style={rotate=90}
]