I'm trying to create a horizontal bar plot with log axis. Adapting several examples I could get what I needed. However, the legend symbols are not being displayed the way I want.
Here's what I got so far:

But I want the legend to look like this:

I tried adding the \addlegendimage but it didn't work at all. In the code below, if I uncomment the commented lines, only the 'FEA' entry will get the correct symbol.
Any ideas on what I'm doing wrong?
MWE:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Time (sec),
legend style={
at={(0.95,-0.2)},
/tikz/every even column/.append style={column sep=0.2cm}},
legend columns=3,
xbar,
xmin=1,
xmode = log,
enlarge y limits=0.2,
height=8cm,
ytick=data, yticklabel style={text width=3cm,align=right},
bar width=10pt,
symbolic y coords={alg 1, alg 2, alg 3, alg 4}, ]
\addplot [fill=black!15!white]
coordinates {
(2.24e+000,alg 4)
(1.91e+000,alg 3)
(1.98e+000,alg 2)
(2.23e+000,alg 1)
};
%\addlegendimage{fill=black!15!white,area legend}
\addlegendentry{Initialization}
\addplot [fill=black!45!white]
coordinates {
(2.69e+003,alg 4)
(1.08e+003,alg 3)
(1.92e+003,alg 2)
(1.02e+003,alg 1)
};
%\addlegendimage{fill=black!45!white,area legend}
\addlegendentry{FEA}
\addplot [fill=black!70!white]
coordinates {
(5.16e+000,alg 4)
(5.18e+000,alg 3)
(5.17e+000,alg 2)
(5.81e+000,alg 1)
};
%\addlegendimage{fill=black!70!white,area legend}
\addlegendentry{Optimization}
\end{axis}
\end{tikzpicture}
\end{document}
Thanks!
area legendinsidelegend style, but it didn't really worked. I have put it inside theaddplotoptions as you suggested and worked beautifully. Thanks! – Regis Feb 19 '14 at 20:09