I am trying to put two boxes in blue and red beside the legend text in a histogram plot. I have tried several things including the one in this link. Unfortunately, the code in the link does not compile for me. I have pgf version 1.7. It is very unfortunate that the code in that link does not work for me. It looks very flexible and powerful.
Here is the code I used:
\begin{tikzpicture}
\begin{axis}[
width=\figurewidth,
height=\figureheight,
scale only axis,
xmode=log,
ymode=log,
xlabel = {Velocity Divergency},
x tick label as interval=false,
xtick={},
xtickten={-18,-16,...,4},
yticklabels={$0.0001\%$, $0.001\%$, $0.01\%$, $0.1\%$, $1\%$, $10\%$, $100\%$},
xmin=1e-18, xmax=1e+4,
ymin=1e-5,ymax=1,
grid=none,
ymajorgrids,
log origin=infty,
bar shift=0pt,
% align right:
legend style={
cells={anchor=west},
legend pos=outer north east,
}
]
\addplot [fill=blue!100,
ybar interval] table [x=Lower, y=Count] {
Lower Upper Count
9.9e-15 1e-14 0.1231
1e-14 1e-13 1e-15
1e-13 1e-12 0.0000
1e-12 1e-11 0.0000
1e-11 1e-10 0.0000
1e-10 1e-9 0.0000
1e-9 1e-8 0.0000
1e-8 1e-7 0.0001
1e-7 1e-6 0.0001
1e-6 1e-5 0.0004
1e-5 1e-4 0.0010
1e-4 1e-3 0.0048
1e-3 1e-2 0.0313
1e-2 1e-1 0.1562
1e-1 1e+0 0.3464
1e+0 1e+1 0.2684
1e+1 1e+2 0.0645
1e+2 1e+3 0.0036
1e+3 1e+4 1e-15
};
\addlegendentry[blue]{Interp}
\addplot [fill=red!100, ybar interval] table [x=Lower, y=Count] {
Lower Count
1e-17 1
1e-16 1
};
\addlegendentry[red]{Div-free}
\end{axis}
\end{tikzpicture}
The above code results in the following figure:
Could someone please help me add two solid rectangles beside the legend texts so that the reader easily finds the corresponding dataset, similar to the following?

