Tikz 条形图组内条形之间的空间

Tikz 条形图组内条形之间的空间

我有以下条形图:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
              legend style={at={(1.2,1)},anchor=north},
              ybar,
              xticklabels={},
              bar width=0.6cm,
              width=5cm,
              height=5cm,
              grid=none,
              ymin=0,
              nodes near coords, style={xshift=0pt,yshift=0pt,anchor=north,font=\footnotesize},
              ]

            \addplot plot coordinates {(1, 3.0)};
            \addplot plot coordinates {(1, 0.7)};
            \addplot plot coordinates {(1, 0.9)};

            \legend{A, B, C}
        \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

我的问题是:如何增加条之间的空间?

答案1

因此,如果您不需要任何更复杂的解决方案,则以下方法应该有效:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        pgfplotsset{
            ytick style={draw=none},
        }
    \begin{axis}[
          ybar=2pt, % change this of you have more than one bar per column
          x=0.9cm, % just play with the relation of these
          bar width=0.1cm, % just play with with the relation of these
          bar shift=0,
          height=5cm,
          width=5cm,
          grid=none,
          ymin=0,
          ymax=5,
          symbolic x coords={A,B,C},
          xmin=A,
          xmax=C,
          enlarge x limits=0.5,
          ytick pos=left,
          ytick={0,...,5},
          xtick pos=left,
          xtick={A,...,C},
          tick align=outside,
          nodes near coords,
          style={xshift=0pt,yshift=0pt,anchor=north,font=\footnotesize},
          ]

        \addplot coordinates {(A, 3.0)};
        \addplot coordinates {(B, 0.7)};
        \addplot coordinates {(C, 0.9)};

    \end{axis}
\end{tikzpicture}
\end{document}

只需调整 x 和条形宽度,这应该适用于您的图。不过,已经有很多示例和论坛条目可以为您提供答案,所以下次也许可以尝试谷歌搜索 ;)。

相关内容