I have a bar chart where some of the data set do not contains points for all the x coordinates.

I have two problems:

  1. Legends labels do not show up
  2. The symbol in the the legend is a double bar. Why is that? Should not it be a single bar?

Also, since I have lot of empty space inside the chart (north west corner), can I put the legend there?




\pgfplotsset{height=6cm, compat=1.9}


\newcommand \SingleName {Single}
\newcommand \DoubleName {Double}
\newcommand \ScalarName {Scalar}
\newcommand \SSEName {SSE}
\newcommand \AVXName {AVX} 

\newcommand \MorinOffsetName {Khuong Offset}
\newcommand \MorinBranchyName {Khuong Branchy}
\newcommand \LowerBoundName{lower\_bound}
\newcommand \BitSetNoPadName{Lead Bit No Pad}
\newcommand \ClassicModName{Classic Mod}

\newcommand \ClassicName {Classic}
\newcommand \ClassicColor {magenta}
\newcommand \ClassicMark {*}
\newcommand \ClassicStyle {solid}

\newcommand \ClassicOffsetName {Offset}
\newcommand \ClassicOffsetColor {green}
\newcommand \ClassicOffsetMark {*}
\newcommand \ClassicOffsetStyle {solid}

\newcommand \BitSetName {Lead Bit}
\newcommand \BitSetColor {green}
\newcommand \BitSetMark {*}
\newcommand \BitSetStyle {solid}

\newcommand \EytzingerName {Eytzinger}
\newcommand \EytzingerColor {blue}
\newcommand \EytzingerMark {*}
\newcommand \EytzingerStyle {solid}

\pgfplotsset{every axis/.append style={
        line width=0.6pt,

    width  = 0.85\textwidth,
    height = 5cm,
    major x tick style = transparent,
    bar width=2.5pt,
    ymajorgrids = true,
    ylabel = {Throughput},
    ytick={0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600},
    symbolic x coords={\ClassicName,\LowerBoundName,\MorinBranchyName,\MorinOffsetName, \ClassicModName,\ClassicOffsetName,\BitSetName,\EytzingerName},
    xtick = data,
    xticklabel style={rotate=45, anchor=east},
    scaled y ticks = false,
    enlarge x limits=0.08,
    legend pos=outer north east,

coordinates {(\EytzingerName,170.465) (\BitSetName,199.79) (\ClassicOffsetName,184.861) (\MorinOffsetName,146.236) (\MorinBranchyName,64.4379) (\ClassicName,53.0333) (\LowerBoundName,62.4723) (\ClassicModName,152.575) };
coordinates {(\EytzingerName,171.929) (\BitSetName,199.421) (\ClassicOffsetName,187.638) (\MorinOffsetName,147.191) (\MorinBranchyName,63.5857) (\ClassicName,50.8408) (\LowerBoundName,63.7888) (\ClassicModName,153.149) };
coordinates {(\EytzingerName,381.08) (\BitSetName,383.956) (\ClassicOffsetName,379.795) (\ClassicModName,244.268) };
coordinates {(\EytzingerName,260.645) (\BitSetName,263.8) (\ClassicOffsetName,254.917) (\ClassicModName,151.602) };
coordinates {(\EytzingerName,385.152) (\BitSetName,386.348) (\ClassicOffsetName,381.327) (\ClassicModName,253.413) };

    coordinates {(\EytzingerName,264.892) (\BitSetName,216.624) (\ClassicOffsetName,214.466) (\ClassicModName,138.059) };

 %   \legend={a,b,c,d,e,f}

\caption{Throughput in millions of searches per second with array X of size $N=15$ and array $Z$ of size $M=2048$ randomly generated}


enter image description here

  • 1
    1. Remove = before legend. So write \legend{ instead of \legend={. 2. Add \pgfplotsset{compat=1.14, /pgfplots/ybar legend/.style={ /pgfplots/legend image code/.code={% \draw[##1,/tikz/.cd,yshift=-0.25em] (0cm,0cm) rectangle (3pt,0.8em);}, }, } to your preamble. Related links tex.stackexchange.com/a/359221/124842, tex.stackexchange.com/a/224677/124842.
    – Bobyandbob
    Jul 1, 2017 at 14:41
  • 1
    3. Yes you could use legend pos=north west,
    – Bobyandbob
    Jul 1, 2017 at 14:44
  • @Bobyandbob Why not just write up an answer? Jul 2, 2017 at 9:16
  • @TorbjørnT. I think its more or less a duplicate to other questions and a simple mistake. Do you think an answer is necessary here?
    – Bobyandbob
    Jul 2, 2017 at 9:21
  • @Bobyandbob Perhaps not, part of my reason for asking is that there's three separate issues. But I can close as dupe of tex.stackexchange.com/q/224676 if you think that's better, and perhaps find an additional dupe for the legend position. Jul 2, 2017 at 9:31


Browse other questions tagged .