2

I would like the pattern lines of the bars to have the same color as the bar lines. How can I do that? If I add it in the pattern statement I get an error.

postaction={pattern=north west lines black!70}

The addition of black!70 cause an error.

\documentclass[preprint,1p,times]{elsarticle}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\newcommand \SingleName {Single}
\newcommand \DoubleName {Double}
\newcommand \ScalarName {Scalar}
\newcommand \SSEName {SSE}
\newcommand \AVXName {AVX}

\newcommand \MorinOffsetName {KhuongOffset}
\newcommand \MorinBranchyName {KhuongBranchy}
\newcommand \BitSetNoPadName{LeadBitNoPad}
\newcommand \ClassicModName{ClassicMod}
\newcommand \ClassicName {Classic}
\newcommand \ClassicOffsetName {Offset}
\newcommand \BitSetName {LeadBit}
\newcommand \EytzingerName {Eytzinger}

\begin{document}
    \begin{figure}[ht]
\begin{tikzpicture}
    \begin{axis}[
        width  = 1*\textwidth,
        height = 5.5cm,
        major x tick style = transparent,
        ybar=3*\pgflinewidth,
        bar width=3pt,
        ymajorgrids = true,
         yminorgrids=true,
        minor y tick num=4,
      %  ylabel = {Throughput},
        ytick={0, 50,..., 1000},
        symbolic x coords={\ClassicName,\LowerBoundName,\MorinBranchyName,\MorinOffsetName,\ClassicModName,\BitSetNoPadName,\ClassicOffsetName,\BitSetName,\EytzingerName},
        xtick = data,
        ylabel style = {font=\footnotesize},
        yticklabel style = {font=\footnotesize},
        xticklabel style={rotate=45, anchor=east,font=\footnotesize},
        scaled y ticks = false,
        enlarge x limits=0.08,
        ymin=0,
        ymax=410,
        legend pos=north west,
        legend style={font=\footnotesize},
    ]



\addplot[style={black!20,fill=white,postaction={pattern=north east lines}}]
coordinates {(\EytzingerName,253.338) (\BitSetName,261.189) (\ClassicOffsetName,250.586) (\BitSetNoPadName,244.75) (\ClassicModName,134.799) };
\addplot[style={black!60,fill=white,postaction={pattern=north west lines}}]
coordinates {(\EytzingerName,401.222) (\BitSetName,399.666) (\ClassicOffsetName,399.58) (\BitSetNoPadName,392.954) (\ClassicModName,248.516) };

       \legend{\SingleName-\ScalarName,\DoubleName-\ScalarName,\SingleName-\SSEName,\DoubleName-\SSEName,\SingleName-\AVXName,\DoubleName-\AVXName}
    \end{axis}
\end{tikzpicture}
\vspace*{-6mm}
\caption{Throughput in millions of searches per second with array X of size $N=15$ and array $Z$ of size $M=2048$ randomly populated}
\label{fig:selectbinary}
\end{figure}

\end{document}

1 Answer 1

3

To achieve that simply add pattern color=. to the \addplot options. The dot is a shortcut for the current color.

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{patterns}
        \newcommand\SingleName{Single}
        \newcommand\DoubleName{Double}
        \newcommand\ScalarName{Scalar}
        \newcommand\SSEName{SSE}
        \newcommand\AVXName{AVX}
        \newcommand\MorinOffsetName{KhuongOffset}
        \newcommand\MorinBranchyName{KhuongBranchy}
        \newcommand\BitSetNoPadName{LeadBitNoPad}
        \newcommand\ClassicModName{ClassicMod}
        \newcommand\ClassicName{Classic}
        \newcommand\ClassicOffsetName{Offset}
        \newcommand\BitSetName{LeadBit}
        \newcommand\EytzingerName{Eytzinger}
\begin{document}
\begin{tikzpicture}[
    font=\footnotesize,                     % <-- (moved here)
]
    \begin{axis}[
        width=1*\textwidth,
        height=5.5cm,
        major x tick style={
            draw=none,                      % <-- (replaced `transparent')
        },
        ybar=3*\pgflinewidth,
        bar width=3pt,
        ytick distance=50,                  % <-- (replaced `ytick=...')
        symbolic x coords={
            \ClassicName,
            \LowerBoundName,
            \MorinBranchyName,
            \MorinOffsetName,
            \ClassicModName,
            \BitSetNoPadName,
            \ClassicOffsetName,
            \BitSetName,
            \EytzingerName,
        },
        xtick=data,
        xticklabel style={
            rotate=45,
            anchor=east,
        },
        enlarge x limits=0.08,
        ymin=0,
        ymax=410,
        legend pos=north west,
    ]
        \addplot [
            black!20,
            fill=white,
            pattern=north east lines,
            pattern color=.,                % <-- added
        ] coordinates {
            (\EytzingerName,253.338)
            (\BitSetName,261.189)
            (\ClassicOffsetName,250.586)
            (\BitSetNoPadName,244.75)
            (\ClassicModName,134.799)
        };
        \addplot [
            black!60,
            fill=white,
            pattern=north west lines,
            pattern color=.,
        ] coordinates {
            (\EytzingerName,401.222)
            (\BitSetName,399.666)
            (\ClassicOffsetName,399.58)
            (\BitSetNoPadName,392.954)
            (\ClassicModName,248.516)
        };

        \legend{
            \SingleName-\ScalarName,
            \DoubleName-\ScalarName,
        }
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .