# Prevent pgfplot line clipping without extending axis

By default pgfplots has a nasty habit of cutting peaks off Adding enlarge y limits={abs=0.6pt} seems to fix this But now I have an unsightly stub at the ends of my axis

I'd rather like to get rid of this, but can't see how. If someone could point my in the right direction that would be very much appriciated :)

## MWE

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{
no marks,
axis lines=middle,
axis on top,
every axis plot/.append style={very thick},
enlarge y limits={abs=0.6pt}, % prevent clipping of plot lines
}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[domain=0:pi]
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}


### Issue with the clip=false solution

This was suggested, and does indeed seem to solve this issue, however it creates another. For asymptotic functions (e.g. changing to 1/x with ymax=5) then produce their own set of issues. Given that this is going inside a global setting, I'd rather not have to worry about this.

### Issue with shorten inner axis line

When plotting some other functions (e.g. 1/(x+1)), the origin develops a 'gap'.

• Does enlarge y limits={abs=0.6pt, upper} work? Sep 28, 2019 at 18:08
• It would, however with something exact (line this sine graph) there's still a visual niggle (just at the top). Also, I'd rather (if possible) have this as a "set and forget" type thing, so I won't have to switch for graphs with a negative minimum, or positive maximum. Sep 28, 2019 at 18:12
• Could you add the code of that example to your question? Makes it easier to test. Sep 28, 2019 at 18:15
• Sure :) I'll cut it down a bit for practicality though Sep 28, 2019 at 18:19
• NB: For the visual niggle with the top, by exact I mean the maximum is exactly one of the tick-marks. I.e. for sine max value=1, so there's a little stub beyond that tick mark. Sep 28, 2019 at 18:35

I don't know if this will work for all cases, but possibly the combination

    enlargelimits={abs=0.6pt},
inner axis line style={shorten >=0.6pt, shorten <=0.6pt}


will work. The first will extend the axis limits by a bit more than half the line width, which will also extend the axis lines. The second line will shorten the axis lines by the same amount.

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{
no marks,
axis lines=middle,
axis on top,
every axis plot/.append style={very thick},
enlargelimits={abs=0.6pt},
inner axis line style={shorten >=0.6pt, shorten <=0.6pt}
}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[domain=0:pi]

• @tecosaur Well, depends a bit on how you look it. The question of how to set the line cap for plot lines is not a duplicate of this. But the line cap wasn't really the problem, the problem was the same as here: that pgfplots clips off everything outside the axis limits, and when the axis limits are the same as the data limits, about half the line width is cut off. Sep 28, 2019 at 19:08