我正在尝试创建一些好看的条形图,但这对我来说似乎不是一件容易的事:)我已经从以下内容开始:
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
width=12cm, height=3.5cm, enlarge y limits=0.5,
xlabel={Value},
symbolic y coords={Instance1,Instance2},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
cycle list name=exotic
]
\addplot coordinates {(3,Instance1) (7,Instance2)};
\addplot coordinates {(2,Instance1) (3,Instance2)};
\end{axis}
\end{tikzpicture}
如下所示:
相反,我更愿意只填充条形图而不绘制和标记。不过,我仍然想使用循环列表。关于如何实现这一点,您有什么想法吗?
答案1
您可以使用
every axis plot/.append style={fill,draw=none,no markers}
作为环境的一种选择axis
。
代码:
\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
width=12cm, height=3.5cm, enlarge y limits=0.5,
xlabel={Value},
symbolic y coords={Instance1,Instance2},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
cycle list name=exotic,
every axis plot/.append style={fill,draw=none,no markers}% <- added
]
\addplot coordinates {(3,Instance1) (7,Instance2)};
\addplot coordinates {(2,Instance1) (3,Instance2)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
像这样:
其获取方式如下:
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
width=12cm, height=3.5cm, enlarge y limits=0.5,
xlabel={Value},
symbolic y coords={Instance1,Instance2},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
cycle list name=exotic
]
\addplot[draw=none,mark=none,fill=blue]
coordinates {(3,Instance1) (7,Instance2)};
\addplot[draw=none,mark=none,mark=none,fill=red]
coordinates {(2,Instance1) (3,Instance2)};
\end{axis}
\end{tikzpicture}\end{document}
酒吧颜色根据您的喜好设置。