我的 ybars 粘在 yaxis 上。如何增加轴和第一个条之间的水平空间,使它们更紧凑?我已经尝试设置 x = 5cm,但我只是想让它们更靠近一点。
\documentclass[fullpage, 12pt, a4paper, doublespacing]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\definecolor{transfertoserver}{HTML}{D7191C}
\definecolor{database}{HTML}{FDAE61}
\definecolor{transfertoclient}{HTML}{ABDDA4}
\definecolor{rendering}{HTML}{2B83BA}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
ybar=8pt,%=8pt, % configures ‘bar shift’
% enlargelimits=0.25,
% bar width=12pt,
% x=6cm,
ylabel={Number of Instances},
ymin=0,
% legend pos= outer north east,
symbolic x coords={training set, test set},
xtick=data,
nodes near coords,
]
\addplot[fill=transfertoclient] coordinates {(test set, 35) (training set, 218)};\addlegendentry{Hits}
\addplot[fill=rendering] coordinates {(test set, 5) (training set, 142)};\addlegendentry{Non-hits}
\end{axis}
\end{tikzpicture}
\caption{Class distribution of the split training and test sets.}
\label{fig:bal2}
\end{figure}
\end{document
答案1
只需将此选项添加到轴上:enlarge x limits=0.5
然后调整值即可获得所需的效果。另请参阅使用符号坐标时按绝对值放大限值
\documentclass[fullpage, 12pt, a4paper, doublespacing]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\definecolor{transfertoserver}{HTML}{D7191C}
\definecolor{database}{HTML}{FDAE61}
\definecolor{transfertoclient}{HTML}{ABDDA4}
\definecolor{rendering}{HTML}{2B83BA}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar=8pt,%=8pt, % configures ‘bar shift’
enlarge x limits=0.7,
ylabel={Number of Instances},
ymin=0,
symbolic x coords={training set, test set},
xtick=data,
nodes near coords,
]
\addplot[fill=transfertoclient] coordinates {(test set, 35) (training set, 218)};\addlegendentry{Hits}
\addplot[fill=rendering] coordinates {(test set, 5) (training set, 142)};\addlegendentry{Non-hits}
\end{axis}
\end{tikzpicture}
\end{document}