[Tex/LaTex] pgfplot column chart legend shape

legendpgfplots

I have the following code in Latex using gpfplot. The legend in the generated graph always looks like the image attached. There are two boxes instead of one for each entry. Why this is happening? How can I modify the legend so that is only one box for each entry.

(Also, how to make the y axis showing actual value instead of 3*10^6)

It looks like I can not post images. So the legend looks like this:
[box1_blue] [box2_blue] entry1
[box1_red] [box2_red] entry2

\begin{tikzpicture}
\begin{axis}[
    ybar,
    tick label style={font=\small},
    tickpos=left,
    xticklabels={double, 20 digits,7 digits, 6 digits, 5 digits}, 
    xtick={1,2,3,4,5},
    ymin=0,
    legend entries={entry1,entry2}
    ]
    \addplot +[bar shift=-.2cm] coordinates {(1,3103533) (2,571651) (3,240729) (4,218595)     (5,207303)};

    \addplot  +[bar shift=.2cm]coordinates {(1,519042) (2,86885) (3,46461) (4,44745) (5,43960)};

\end{axis}
\end{tikzpicture}

Best Answer

Another way to change the legend is to use area legend in the \addplot.

To adjust the y tick label style you can use y tick label style as shown below:

enter image description here

If you comment out the fixed setting you get the scientific notation for the y-ticks:

enter image description here

Code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document} 
\begin{tikzpicture}
\begin{axis}[
    ybar,
    tick label style={font=\small},
    tickpos=left,
    xticklabels={double, 20 digits,7 digits, 6 digits, 5 digits}, 
    xtick={1,2,3,4,5},
    ymin=0,
    legend entries={entry1,entry2},
    y tick label style={/pgf/number format/.cd,%
          scaled y ticks = false,
          set thousands separator={},
          fixed
    },
    ]
    \addplot +[bar shift=-.2cm, area legend] coordinates {(1,3103533) (2,571651) (3,240729) (4,218595)     (5,207303)};

    \addplot  +[bar shift=.2cm, area legend]coordinates {(1,519042) (2,86885) (3,46461) (4,44745) (5,43960)};
\end{axis}
\end{tikzpicture}
\end{document}
Related Question