latexpgfplots

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


I'd like to draw a line plot the years on the x-axis with xmax = 2020 in LateX pgfplots. As my data ends in 2019 I get a vertical line at 2019. It's probably quite easy but I didn't find anything about how to avoid that.

Thanks in advance!

Example code:

\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}

Solution

  • With \closedcycle you explicitly add the line

    \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}
    

    enter image description here