2

I want to plot as compact as possible using pgfplots.

I have the following piece of code:

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
            width=7.5cm,
            xlabel={Size of the data set list},
            ylabel={Gas cost},
            grid=major,
            domain=1:100,
            xmin=0,xmax=10,
            ymin=0,ymax=10,
            ytick={0,2,...,12},
            samples=21,
        ]
        \addplot {x};
    \end{axis}
\end{tikzpicture}
\end{document}

With the following output:

enter image description here

I don't know why but there is extra new-line between the y-axis's label and its line. How can I remove the extra-space between y-axis's label and y-axis line?

Bernard
  • 271,350
alper
  • 1,389
  • I can't reproduce your problem (tested by pgfplots version 1.18). You can define y label style with smaller inner sep, for example inner sep=1pt. – Zarko Apr 15 '22 at 12:57
  • 1
    @Zarko That is because of the compat setting. Any compat setting of 1.3 or higher activates a better method for placing axis labels. – Torbjørn T. Apr 15 '22 at 13:18
  • @TorbjørnT. I believe I was using \pgfplotsset{compat = newest} should I use 1.3 instead of newest – alper Apr 15 '22 at 13:19
  • @alper I didn't say that, I said that any valid option for compat with a version number higher than 1.3 will improve the position of the y-axis label. I would probably use the setting corresponding to the pgfplots version you have installed, so if you're up to date, that is compat=1.18. (By the way, latest isn't a valid option for compat. There is a newest option, but it is not recommended to use that: https://tex.stackexchange.com/q/139690/) – Torbjørn T. Apr 15 '22 at 13:28
  • (The comment above was written before I saw that you edited your comment.) – Torbjørn T. Apr 15 '22 at 13:30
  • When I checkted the log file current installed version for pgfplots is v1.18.1, hence compat=1.18 is used. But still the extra space remains :-( – alper Apr 15 '22 at 16:28
  • 3
    No, the installed version and the compat setting are not the same. You need to actually have the codeline \pgfplotsset{compat=1.18} in your document. – Torbjørn T. Apr 15 '22 at 18:14

1 Answers1

2

Even though your installed version is v1.18.1, you have to set the compat option explicitly to request that all features of version 1.18 are used. If you omit it, you get the following warning in the log:

Package pgfplots Warning: running in backwards compatibility mode
(unsuitable tick labels; missing features). Consider writing
\pgfplotsset{compat=1.18} into your preamble. on input line 4.

MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
            width=7.5cm,
            xlabel={Size of the data set list},
            ylabel={Gas cost},
            grid=major,
            domain=1:100,
            xmin=0,xmax=10,
            ymin=0,ymax=10,
            ytick={0,2,...,12},
            samples=21,
        ]
        \addplot {x};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Ah I never check the log file that has the compilation output, next time I should :-) – alper Apr 15 '22 at 19:07