[Tex/LaTex] Automatically get (ymin,ymax) and (xmin,xmax) in pgfplots

pgfplotstikz-pgf

I am plotting some 2D data from a file using pgfplots. Is it possible to automatically get (ymin,ymax) and (xmin,xmax) from the file I am trying to plot? I don't want to keep changing these each time I plot a different file.

Not setting these ranges will leave some undesired white spaces in my plots.

Best Answer

To prevent PGFPlots from adding padding around your data, set enlargelimits=false:

\documentclass[]{article}

\usepackage{pgfplots}

\begin{document}
Default settings:

\begin{tikzpicture}
\begin{axis}
\addplot table {
3 2
5 3
9 11
};
\end{axis}
\end{tikzpicture}

\hspace{2cm}


With \verb|enlargelimits=false|:

\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot table {
3 2
5 3
9 11
};
\end{axis}
\end{tikzpicture}
\end{document}
Related Question