How to remove the blank space in tikz?

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=none,axis equal]

\end{axis}
\end{tikzpicture}
\end{document}


Here is the code to draw a tikz figure as this:

How could I remove those blank space, to make the figure more compact?

Thanks

• Where you have blank space? Your code can not be compiled, so we can only guess what is your problem. For test, draw your graph with axis that you will see, where is your curve and where is blank space. Maybe is problem in axis equal. – Zarko Mar 12 '16 at 19:56
• Use \pgfplotsset{compat=1.13} (or anything 1.8 or after). pgfplots even gives you a warning that you lose functionality when you do not set this key. – Paul Gessler Mar 12 '16 at 20:10
• use hide axis key – percusse Mar 12 '16 at 20:17
• You might try specifying the width and height of the axis. Note that pgfplots regards these as suggestions, not rules. – John Kormylo Mar 12 '16 at 20:19

Horizontal space is added because enlargelimits is true by default. You get a lot of vertical space because of axis equal it seems. A workaround is to set ymin and ymax explicitly, I don't know of any more automatic ways of doing that, though there might be one. In the code below clip=false is added because otherwise half the thickness of the horizontal lines would be clipped away. Different values for ymin/ymax would make that unnecessary.

The red rectangle shows the bounding box of the tikzpicture.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
hide axis,
enlargelimits=false,
ymin=0,
ymax=1,
axis equal,
clip=false]

x y1
0 1
1 1
1 0
4 0
};

\end{axis}
\draw [red] (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{document}


The changes in Torbjørn's answer are already incorporated to the underlying code behind the hide axis key, which is set when using axis lines=none. pgfplots has an extensive mechanism to ensure backward compatibility, so that existing plots look the same even if the pgfplots package has been updated.

To take advantage of this, always set pgfplots' compat key. There is even a warning if you do not set it:

Package pgfplots Warning: running in backwards compatibility mode (unsuitable t
ick labels; missing features). Consider writing \pgfplotsset{compat=1.13} into


Without a setting for the compat key, pgfplots goes into a "fallback" mode, where all keys have the effect they had at the time they were introduced. Here, this means we are not seeing improvements to the hide axis key introduced in version 1.8.

Set compat to 1.8 or later (1.13 is current as of the time of writing) to access the improvements to the hide axis code:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13} % or anything >= 1.8

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=none,axis equal]
\addplot+[no markers,thick] coordinates {(0,0) (1,0) (1,1) (2,1)};
\end{axis}
\end{tikzpicture}
\end{document}


It is recommended to set the key to the current version when you are creating the plot, unless you have a specific need for the older versions. This way, you get all the latest features/fixes, but if you revisit the document in the future, the plot will keep the same appearance until you choose to change the compat key setting.