![tikz 图表中的密度和重叠](https://linux22.com/image/329085/tikz%20%E5%9B%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%AF%86%E5%BA%A6%E5%92%8C%E9%87%8D%E5%8F%A0.png)
我现在得到了我的图表的以下代码:
\begin{figure}
\setlength{\fboxrule}{0pt}
\fbox{
\vspace*{-100pt}
\begin{tikzpicture}[every node/.style={font=\scalefont{1}}]
\centering
\begin{axis} [
height=0.9\textheight, width=0.9\textwidth,
xbar, xmin=0,
tick align=inside,
tickwidth = 0pt,
symbolic y coords={%
{Others},
{Test cases},
{Error reports},
{Screenshots},
{Stack traces},
{Steps to reproduce},
{Expected behavior},
{Observed behavior},
{Summary},
{Hardware,...},
{Severity},
{Version}, {Product/App name}},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
xlabel={Percentage of votes},
]
\addplot +[area legend] coordinates {
(33.33,{Product/App name})
(58.33,{Version})
(8.33,{Severity})
(50,{Hardware,...})
(25,{Summary})
(58.33,{Observed behavior})
(25,{Expected behavior})
(75,{Steps to reproduce})
(58.33,{Stack traces})
(25,{Screenshots})
(25,{Error reports})
(0,{Test cases})};
\addplot +[area legend] coordinates {
(30.95,{Product/App name})
(61.90,{Version})
(26.19,{Severity})
(69.05,{Hardware,...})
(21.43,{Summary})
(59.52,{Observed behavior})
(28.57,{Expected behavior})
(88.10,{Steps to reproduce})
(45.24,{Stack traces})
(30.95,{Screenshots})
(33.33,{Error reports})
(14.29,{Test cases})};
legend cell align = left,
\legend{Desktop, Mobile }
\end{axis}
\end{tikzpicture}
}
\caption{Comparison of important information}
\label{fig:importantcriteria}
\end{figure}
创建此条形图
问题在于一个重叠的 88.1 值,我还想让这些条形图彼此更接近一些,这样我就可以节省一些空间。此外,最后一根条形图和 xa 之间的空间
尝试了一下,enlargelimits
但是这会在四面八方产生裕度,但我更喜欢从左侧轴开始的条形图(至少我认为这样看起来更好)。
答案1
您可以通过更改 的可选参数来避免条形图彼此分离xbar
,并且每组条形图之间的间距由图形的整体高度设置,因为 PGFplots 会将它们全部展开。此外,您可以放大上部X通过使用 来限制enlarge x limits=upper
。我通过将值设置为0.15
似乎适合此图的值来进一步调整它。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
height=13cm,
width=10cm,
xbar=0pt,
bar width=1em,
xmin=0,
xlabel={Percentage of votes},
ytick=data,
enlarge x limits={upper,value=0.15},
tick align=inside,
tickwidth = 0pt,
symbolic y coords={%
{Others},
{Test cases},
{Error reports},
{Screenshots},
{Stack traces},
{Steps to reproduce},
{Expected behavior},
{Observed behavior},
{Summary},
{Hardware,...},
{Severity},
{Version},
{Product/App name}
},
nodes near coords,
nodes near coords align={horizontal},
]
\addplot +[area legend] coordinates {
(33.33,{Product/App name})
(58.33,{Version})
(8.33,{Severity})
(50,{Hardware,...})
(25,{Summary})
(58.33,{Observed behavior})
(25,{Expected behavior})
(75,{Steps to reproduce})
(58.33,{Stack traces})
(25,{Screenshots})
(25,{Error reports})
(0,{Test cases})};
\addplot +[area legend] coordinates {
(30.95,{Product/App name})
(61.90,{Version})
(26.19,{Severity})
(69.05,{Hardware,...})
(21.43,{Summary})
(59.52,{Observed behavior})
(28.57,{Expected behavior})
(88.10,{Steps to reproduce})
(45.24,{Stack traces})
(30.95,{Screenshots})
(33.33,{Error reports})
(14.29,{Test cases})
};
% legend cell align = left, \legend{Desktop, Mobile }
\end{axis}
\end{tikzpicture}
\end{document}
请注意,我没有包括图例,因为您似乎在 MWE 中错过了它的部分代码。