\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {ring enrich.},
ybar,
width=10cm,
xtick={1,2},
xticklabels={%
before,
after,
}]
\addplot[
fill=blue!25,
draw=black,
error bars/.cd,
y dir=both,
y explicit
]
table [y error=error] {
x y error
1 6.63 3.95
};
\addplot[
fill=red!25,
draw=black,
error bars/.cd,
y dir=both,
y explicit
]
table [y error=c] {
x y c
2 41.58 8.48
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以通过设置 来将条形图拉近,同时保持整体图宽度不变enlarge x limits=<value>
,其中<value>
指定要增加轴范围的分数。要使条形图更宽,您可以设置bar width=<width>
:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar, bar shift=0pt,
bar width=1cm,
enlarge x limits=0.5,
width=10cm,
xtick={1,2},
]
\addplot[
fill=blue!25,
draw=black
]
table{
x y error
1 6.63 3.95
};
\addplot[
fill=red!25,
draw=black
]
table {
x y c
2 41.58 8.48
};
\end{axis}
\end{tikzpicture}
\end{document}