5

I would like to have my vertical axis 1.0 above the maximum value and 1.0 beneath the minimum value (implicit). Though that enlarge y limits would do the job, however it does not. I'm not sure how this function actually works and if it is the correct approach to solve my problem.

With my MWE, the vertical range is between 2 and 7, so I would like to have my vertical axis set between 1 and 8. Implicit of the plotted values; so ymin=1 and ymax=8 is not an answer.

Here's my MWE

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{csvsimple}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
    x,value
    0, 3
    5, 6
    14, 7
    31, 2
\end{filecontents*}

\begin{document}
    \begin{tikzpicture}
    \centering
    \begin{axis}[
    enlarge y limits = 1
    ]
    \addplot table [x=x, y=value, col sep=comma] {data.csv};
    \end{axis}
    \end{tikzpicture}
\end{document}
  • 2
    Use enlarge y limit={abs=1}. – Jake Feb 17 '16 at 09:57
  • For a reference: chapter 4.14, page 273 (in the manual of the 2.xx version, which is the one I have on Ubuntu). – Rmano Feb 17 '16 at 09:59
  • Thanks, it is clear to me. If no abs is specified, does it enlarge by pt's? – Joost Döbken Feb 17 '16 at 10:03
  • 1
    No, it will enlarge relatively to the computed range. 0.2 means 20% --- @Jake, what about writing an answer? ;-) – Rmano Feb 17 '16 at 10:31
  • 1
    @Rmano: Would you mind writing one? You've added all that useful information, my comment was really just meant to get the OP back on track quickly while someone writes a proper answer explaining how the enlarge y limits key works – Jake Feb 17 '16 at 10:48

1 Answers1

5

By default, as you can see in the manual (chapter 4.14, page 273, in the manual of the 2.xx version), you have a relative enlargement:

/pgfplots/enlarge y limits=auto|true|false|upper|lower| val |value=val |abs value= val | abs= val |rel= val 
(initially auto)

so your enlarge y limits = 1 enlarge the limits of the y axes by 100%; probably you can obtain what you are looking for with a 10% enlargement like enlarge y limits = 0.1 or similar value.

To enlarge it by a fixed value you should do

enlarge y limits={abs=1}

to obtain:

Output

Rmano
  • 40,848
  • 3
  • 64
  • 125