# pgfplot column chart legend shape

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}

-
Welcome to TeX.sx! Please modify your question into a minimal working example (MWE). It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. –  hpesoj626 Nov 12 '12 at 7:07
As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  hpesoj626 Nov 12 '12 at 7:09
I guess the legend entry with two boxes is meant to distinguish box plots from area plots. The latter would get a legend entry with a singular rectangle. –  hakaze Nov 12 '12 at 7:37
Thank you for guys for all your help! –  Ken Ma Nov 12 '12 at 8:44

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:

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

## 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}

-

Try this:

\documentclass{standalone}

\usepackage{tikz, 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},
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
}
]
\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}

\end{document}


I have added legend image code key here to modify the default key for bar charts. Play around with the dimensions of the rectangle for a desired effect.

Please refer the following questions for changing the x/y tick label formats:

-
This does not show the actual y value. –  hpesoj626 Nov 12 '12 at 7:45
You don't need the tikz package. –  Peter Grill Nov 12 '12 at 7:56
@PeterGrill thank you peter. I am getting a strange error: Package pgfkeys Error: I do not know the key '/pgf/number format/at' and I am going to ignore it. Perhaps you misspelled it. when I add the y tick label style to my code. I have used it a hundred times but don't know what went wrong this time. –  devendra Nov 12 '12 at 8:01
Where is the at in /pgf/number format/at coming from? –  Peter Grill Nov 12 '12 at 8:06
/pgf/number format/.cd –  devendra Nov 12 '12 at 8:08