我有一张分组条形图,我想以某种方式突出显示与 EU-24 相对应的两个条形。也许可以通过赋予它们不同的颜色或图案。有什么想法吗?
\documentclass[tikz,border={38pt 12pt}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}\definecolor{mycolor1}{rgb}{0,0,0.5625}
\begin{document}
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[%
width=4.78723958333333in,
height=1.96484375in,
area legend,
scale only axis,
xmin=0,
xmax=12,
xtick={1,2,3,4,5,6,7,8,9,10,11},
xticklabels={IRL,EST,GRC,LTU,CZE,DNK,SVN,ESP,EU-24,GBR,CZE},
xlabel={Country Initials},
ymin=-10,
ymax=10,
ylabel={Percentage},
legend style={draw=black,fill=white,legend cell align=left}
]
\addplot[ybar,bar width=0.0911855158730159in,bar shift=-0.0569909474206349in,fill=mycolor1,draw=black] plot coordinates{(1,6.50839602446152)
(2,7.18649865479679)
(3,5.69926104853342)
(4,8.86318406286013)
(5,5.96722429393004)
(6,3.21245636089815)
(7,3.90148651103934)
(8,4.11307588009999)
(9,4.55138638324477)
(10,4.87923265464318)
(11,2.66698448311287)};
\addlegendentry{2000-2009};
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0 0\\
12 0\\
};
\addplot[ybar,bar width=0.0911855158730159in,bar shift=0.0569909474206349in,fill=red!50!black,draw=black] plot coordinates{(1,-7.93058315856087)
(2,-7.26040844811857)
(3,-6.67854407923318)
(4,-5.0031445973415)
(5,-4.37613983512456)
(6,-2.10591746017944)
(7,-2.00034271729993)
(8,-0.903233231259903)
(9,-0.631822488660329)
(10,-0.47632641303218)
(11,-0.222157097491837)};
\addlegendentry{2009-2012};
\end{axis}
\end{tikzpicture}%
\end{document}
答案1
最简单的方法是从命令中删除 EU-24 点\addplot
并添加 2 个新点\addplot
。这不是最优雅的解决方案,但它可以满足您的要求。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}\definecolor{mycolor1}{rgb}{0,0,0.5625}
\begin{document}
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[%
width=4.78723958333333in,
height=1.96484375in,
area legend,
scale only axis,
xmin=0,
xmax=12,
xtick={1,2,3,4,5,6,7,8,9,10,11},
xticklabels={IRL,EST,GRC,LTU,CZE,DNK,SVN,ESP,EU-24,GBR,CZE},
xlabel={Country Initials},
ymin=-10,
ymax=10,
ylabel={Percentage},
legend style={draw=black,fill=white,legend cell align=left}
]
\addplot[ybar,bar width=0.0911855158730159in,bar shift=-0.0569909474206349in,fill=mycolor1,draw=black] plot coordinates{(1,6.50839602446152)
(2,7.18649865479679)
(3,5.69926104853342)
(4,8.86318406286013)
(5,5.96722429393004)
(6,3.21245636089815)
(7,3.90148651103934)
(8,4.11307588009999)
%(9,4.55138638324477)
(10,4.87923265464318)
(11,2.66698448311287)};
\addlegendentry{2000-2009};
\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0 0\\
12 0\\
};
\addplot[ybar,bar width=0.0911855158730159in,bar shift=0.0569909474206349in,fill=red!50!black,draw=black] plot coordinates{(1,-7.93058315856087)
(2,-7.26040844811857)
(3,-6.67854407923318)
(4,-5.0031445973415)
(5,-4.37613983512456)
(6,-2.10591746017944)
(7,-2.00034271729993)
(8,-0.903233231259903)
%(9,-0.631822488660329)
(10,-0.47632641303218)
(11,-0.222157097491837)};
\addlegendentry{2009-2012};
\addplot[ybar,bar width=0.0911855158730159in,bar shift=0.0569909474206349in,fill=green!50!black,draw=black] plot coordinates{(9,-0.631822488660329)};
\addplot[ybar,bar width=0.0911855158730159in,bar shift=-0.0569909474206349in,fill=green!50!black,draw=black] plot coordinates{(9,4.55138638324477)};
\end{axis}
\end{tikzpicture}%
\end{document}