目前,我绘制了以下条形图:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\definecolor{ref}{rgb}{0.65,0.65,0.65} %{0.4,0.8,0.85}
\definecolor{lhmm}{rgb}{0.9,0.6,0.5}
\definecolor{ghmm}{rgb}{0.7,0.9,0.35}
\definecolor{lsvm}{rgb}{0.9,0.8,0.25}
\definecolor{gsvm}{rgb}{0.4,0.8,0.9}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}[font=\sffamily\scriptsize]
\pgfkeys{
/pgf/number format/precision=1,
/pgf/number format/fixed zerofill=true
}
\begin{axis}[
ybar,
bar width=.2cm,
enlargelimits=0.09,
legend style={at={(0.5,1.15)},
anchor=north,legend columns=-1},
xlabel={Demonstration},
ylabel={Recall [\%]},
width=0.9\linewidth,
height=0.9\linewidth,
symbolic x coords={1,2,3,1+2,1+3,2+3,1+2+3},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={color=black, rotate=67.5, anchor=center, font=\tiny, xshift=7, yshift=3}
]
\addplot [fill=lhmm] coordinates {(1,37.5) (2, 43.8) (3, 62.5) (1+2, 62.5) (1+3, 62.5) (2+3, 62.5) (1+2+3, 62.5)}; % ,postaction={pattern=north east lines}
\addplot [fill=ghmm] coordinates {(1,43.8) (2, 50.0) (3, 68.8) (1+2, 75.0) (1+3, 75.0) (2+3, 75.0) (1+2+3, 75.0)};
\addplot [fill=lsvm]coordinates {(1,81.3) (2, 93.8) (3, 93.8) (1+2, 93.8) (1+3, 93.8) (2+3, 93.8) (1+2+3, 93.8)};
\addplot [fill=gsvm]coordinates {(1,87.5) (2, 100.0) (3, 100.0) (1+2, 100.0) (1+3, 100.0) (2+3, 100.0) (1+2+3, 100.0)};
\legend{L-HMM,G-HMM,L-SVM,G-SVM}
\end{axis}
\end{tikzpicture}
\end{document}
最终的图表就是我想要的,但有一个例外:有几个条形图我想绘制额外的图案,而不是只填充条形图。例如,我想为入口设置东北线(2, 100.0)
。这可能吗?
你好,西蒙。
答案1
谢谢杰克,你的回答让我想到了一个比提出的解决方案简单得多的想法。因为我知道哪个条应该有另一种颜色,所以我可以简单地使用 forget plot 并绘制两个不同的条:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\definecolor{ref}{rgb}{0.65,0.65,0.65} %{0.4,0.8,0.85}
\definecolor{lhmm}{rgb}{0.9,0.6,0.5}
\definecolor{ghmm}{rgb}{0.7,0.9,0.35}
\definecolor{lsvm}{rgb}{0.9,0.8,0.25}
\definecolor{gsvm}{rgb}{0.4,0.8,0.9}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}[font=\sffamily\scriptsize]
\pgfkeys{
/pgf/number format/precision=1,
/pgf/number format/fixed zerofill=true
}
\begin{axis}[
ybar,
enlargelimits=0.09,
bar width = .2cm,
legend style={at={(0.5,1.15)},
anchor=north,legend columns=-1},
xlabel={Demonstration},
ylabel={Recall [\%]},
width=0.9\linewidth,
height=0.7\linewidth,
symbolic x coords={1,2,3,1+2,1+3,2+3,1+2+3},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={color=black, rotate=67.5, anchor=center, font=\tiny, xshift=7, yshift=3}]
\addplot [fill=lhmm, forget plot, postaction={pattern=north east lines}] coordinates {(2, 43.8) (3, 62.5) (1+2, 62.5) (1+3, 62.5) (2+3, 62.5) (1+2+3, 62.5)};
\addplot [fill=lhmm] coordinates {(1,37.5)};
\addplot [fill=ghmm] coordinates {(1,43.8) (2, 50.0) (3, 68.8) (1+2, 75.0) (1+3, 75.0) (2+3, 75.0) (1+2+3, 75.0)};
\addplot [fill=lsvm]coordinates {(1,81.3) (2, 93.8) (3, 93.8) (1+2, 93.8) (1+3, 93.8) (2+3, 93.8) (1+2+3, 93.8)};
\addplot [fill=gsvm]coordinates {(1,87.5) (2, 100.0) (3, 100.0) (1+2, 100.0) (1+3, 100.0) (2+3, 100.0) (1+2+3, 100.0)};
\legend{L-HMM,G-HMM,L-SVM,G-SVM}
\end{axis}
\end{tikzpicture}
\end{document}
当然,这只在我没有使用文件内容的情况下才有效。结果如下: