避免数据末尾的垂直线(LaTeX pgfplots)

Avoid vertical line at the end of data (LaTeX pgfplots)

我想在 LateX pgfplots 中用 xmax = 2020 在 x 轴上画一条线图来绘制年份。当我的数据在 2019 年结束时,我在 2019 年得到一条垂直线。这可能很容易,但我没有找到任何关于如何避免这种情况的信息。

提前致谢!

示例代码:

\documentclass[tikz, border=1mm]{standalone}
\begin{document}


\begin{figure}
    \begin{tikzpicture}
        \begin{axis}[
        width = 0.6\textwidth,
        xticklabel style=
        {/pgf/number format/1000 sep=,rotate=90,anchor=east},
        xmin = 1995, xmax = 2020,
        ymin = 0, ymax = 1.2,
        xlabel = Year,
        ylabel style ={align=center}, ylabel = Specific energy consumption\in kWh/pkm,
        yticklabels={, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2}]
        
        \addplot [] coordinates {
        (1995,1.102) (1996,1.067) (1997,1.048) (1998,0.939) (1999,0.905) (2000,0.901) (2001,0.924) (2002,0.944) (2003,0.906) (2004,0.9) (2005,0.901) (2006,0.89) (2007,0.854) (2008,0.829) (2009,0.813) (2010,0.839) (2011,0.846) (2012,0.831) (2013,0.772) (2014,0.768) (2015,0.785) (2016,0.794) (2017,0.765) (2018,0.755) (2019,0.768) } \closedcycle;
        \end{axis}
    \end{tikzpicture}
\end{figure}

使用 \closedcycle 您明确添加行

\documentclass[tikz, border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}


\begin{figure}
    \begin{tikzpicture}
        \begin{axis}[
        width = 0.6\textwidth,
        xticklabel style=
        {/pgf/number format/1000 sep=,rotate=90,anchor=east},
        xmin = 1995, xmax = 2020,
        ymin = 0, ymax = 1.2,
        xlabel = Year,
        ylabel style ={align=center}, ylabel = Specific energy consumption\in kWh/pkm,
        yticklabels={, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2}]
        
        \addplot [] coordinates {
        (1995,1.102) (1996,1.067) (1997,1.048) (1998,0.939) (1999,0.905) (2000,0.901) (2001,0.924) (2002,0.944) (2003,0.906) (2004,0.9) (2005,0.901) (2006,0.89) (2007,0.854) (2008,0.829) (2009,0.813) (2010,0.839) (2011,0.846) (2012,0.831) (2013,0.772) (2014,0.768) (2015,0.785) (2016,0.794) (2017,0.765) (2018,0.755) (2019,0.768) } 
%        \closedcycle
        ;
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}