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

\addplot+[no markers,thick] table [y=y1, x=x]{p=0_basis.dat};

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

Here is the code to draw a tikz figure as this: enter image description here

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
  • 1
    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
  • 1
    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
2

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.

enter image description here

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

\addplot+[no markers,thick] table [y=y1, x=x]{
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}
| improve this answer | |
1

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 
your preamble.

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}

enter image description here

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.