直方图:增加条形之间的间距

直方图:增加条形之间的间距

我怎样才能保持条形的宽度相同,同时增加条形之间的空间?

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

    \begin{figure}[p]
    \centering  
    \begin{tikzpicture}[font=\footnotesize]
        \begin{axis} [ylabel={Results},
            width=\textwidth,
            height=8cm,
            enlarge x limits=0.03,
            ybar,ymin=0,ymax=1750,xtick=data,
            ymajorgrids=true,xtick pos=left,
            ytick={0, 500, 1000, 1500},
            yticklabels={$0$,$500$,$1000$,$1500$},
            x tick label style=%
            {rotate=90,anchor=east},
            xticklabel interval boundaries,
            symbolic x coords={$1990$,$1991$,$1992$,$1993$,$1994$,$1995$,$1996$,$1997$,$1998$,$1999$,$2000$,$2001$,$2002$,$2003$,$2004$,$2005$,$2006$,$2007$,$2008$,$2009$,$2010$,$2011$,$2012$,$2013$,$2014$,$2015$,$2016$,$2017$,$2018$,$2019$,$2020$},
            ]
            \addplot
            [ybar interval, fill=cyan,
            draw=black] coordinates
            {($1990$, 31) ($1991$, 23) ($1992$, 36) ($1993$, 34) ($1994$, 46) ($1995$, 72) ($1996$, 127) ($1997$, 105) ($1998$, 137) ($1999$, 147) ($2000$, 135) ($2001$, 162) ($2002$, 211) ($2003$, 209) ($2004$, 301) ($2005$, 349) ($2006$, 452) ($2007$, 474) ($2008$, 635) ($2009$, 943) ($2010$, 998) ($2011$, 1047) ($2012$, 1069) ($2013$, 1173) ($2014$, 1236) ($2015$, 1106) ($2016$, 1236) ($2017$, 1329) ($2018$, 1447) ($2019$, 1697) ($2020$, 1291)
            };          
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

我尝试添加bar width=9pt,和消除ybar interval,,但某些条形之间的间距似乎不同。

答案1

像这样?

在此处输入图片描述

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[x=4mm, height=8cm,
    ybar,
    bar width=3mm,
    enlarge x limits=0.02,          
    enlarge y limits={.1, upper},   
ymajorgrids=true,
    minor y tick num=4,   
    xtick=data,
    ytick={0, 500, 1000, 1500},
    yticklabels={0,500,1000,1500},
    x tick label style={rotate=90,anchor=east},
symbolic x coords={ 1990,1991,1992,1993,1994,
                    1995,1996,1997,1998,1999,
                    2000,2001,2002,2003,2004,
                    2005,2006,2007,2008,2009,
                    2010,2011,2012,2013,2014,
                    2015,2016,2017,2018,2019,
                    2020},
                    ]
\addplot coordinates   {(1990, 31)   (1991, 23)   (1992, 36)   (1993, 34)   (1994, 46)
                        (1995, 72)   (1996, 127)  (1997, 105)  (1998, 137)  (1999, 147)
                        (2000, 135)  (2001, 162)  (2002, 211)  (2003, 209)  (2004, 301)
                        (2005, 349)  (2006, 452)  (2007, 474)  (2008, 635)  (2009, 943)
                        (2010, 998)  (2011, 1047) (2012, 1069) (2013, 1173) (2014, 1236)
                        (2015, 1106) (2016, 1236) (2017, 1329) (2018, 1447) (2019, 1697)
                        (2020, 1291)
                       };
    \end{axis}
\end{tikzpicture}
\end{document}

提议的解决方案和您的 MWE 之间的主要区别:

  • 定义钢筋之间的距离 ( x=5mm)
  • 定义条形的宽度 ( bar width=3mm)
  • 已经ybar interval,从...删除\addplot

相关内容