我希望条形图的图案线与条形线具有相同的颜色。我该怎么做?如果我将其添加到图案语句中,则会出错。
postaction={pattern=north west lines black!70}
添加会black!70
导致错误。
\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
要实现这一点,只需添加pattern color=.
到\addplot
选项中。点是当前颜色的快捷方式。
% 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}