![如何调整 TikZ 垂直条形图中的列宽?](https://linux22.com/image/475542/%E5%A6%82%E4%BD%95%E8%B0%83%E6%95%B4%20TikZ%20%E5%9E%82%E7%9B%B4%E6%9D%A1%E5%BD%A2%E5%9B%BE%E4%B8%AD%E7%9A%84%E5%88%97%E5%AE%BD%EF%BC%9F.png)
我使用 TikZ 创建了一个垂直条形图。以下是代码:
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
\begin{axis}[
ybar=0pt,
% enlargelimits=0.15,
width=\columnwidth,
% ymin=90,
ylabel={Number of non-redundant filters},
symbolic x coords={Layer 1, Layer 2, Layer 3, Layer 4, Layer 5},
xtick=data,
bar width=8pt,
legend style={
at={(0.25,1.0)},
anchor=north,
legend columns=1,
},
% legend to name={mylegend},
axis x line*=bottom,
axis y line*=left,
xticklabel style={rotate=0, font=\footnotesize},
]
\addplot [teal, fill, opacity=0.7, nodes near coords,every node near coord/.append style={xshift=5pt,yshift=12pt,font=\footnotesize,rotate=90, opacity=1}]coordinates {(Layer 1, 44) (Layer 2, 78) (Layer 3, 139) (Layer 4, 247) (Layer 5, 227)};
\addplot [orange, fill, opacity=0.7, nodes near coords,every node near coord/.append style={xshift=5pt,yshift=12pt,font=\footnotesize,rotate=90, opacity=1}]coordinates {(Layer 1, 40) (Layer 2, 71) (Layer 3, 121) (Layer 4, 206) (Layer 5, 168)};
\addplot [blue, fill, opacity=0.7, nodes near coords,every node near coord/.append style={xshift=5pt,yshift=12pt,font=\footnotesize,rotate=90, opacity=1}]coordinates {(Layer 1, 38) (Layer 2, 61) (Layer 3, 108) (Layer 4, 186) (Layer 5, 155)};
\addplot [cyan, fill, opacity=0.7, nodes near coords,every node near coord/.append style={xshift=5pt,yshift=12pt,font=\footnotesize,rotate=90, opacity=1}]coordinates {(Layer 1, 38) (Layer 2, 61) (Layer 3, 108) (Layer 4, 184) (Layer 5, 154)};
\addplot [red, fill, opacity=0.7, nodes near coords,every node near coord/.append style={xshift=5pt,yshift=12pt,font=\footnotesize,rotate=90, opacity=1}]coordinates {(Layer 1, 48) (Layer 2, 90) (Layer 3, 166) (Layer 4, 307) (Layer 5, 282)};
\legend{Random search, CHIP \cite{Sui2021CHIPCI}, FPC \cite{chen2022fpc}, SPSRC \cite{sun2024towards}, GEM (Ours)}
\end{axis}
\end{tikzpicture}
% \ref{mylegend}
\caption{Non-redundant selected filters with SVGG.}
\label{fig:rank}
\end{figure}
但是,我面临的问题是列太多(每个类别 5 个),这导致某些列被截断,并且每个类别(第 1 层与第 2 层)之间的空间太小。我该如何设置列的宽度以使其变小并将它们全部放入图片中?
此外,我希望得到有关重构此图以使其更具视觉吸引力的建议。我正在考虑将其转换为水平条形图。
在此先感谢您的帮助。