3
  • I want to use extra y ticks in a pgfplots diagram.
  • With \pgfplotsset{compat=newest} the ylabel is dancing (not watnted).

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest} % <-- Causes dancing y label when adding  'extra y ticks'

\pgfplotsset{myDefaultStyle/.style = 
    {
    width = 160mm,
    height = 90mm,
    axis x line = bottom,
    axis y line = left,
    ylabel = y Label,
    xlabel = x Label,   
    grid = major,
    }}

\begin{document}

% ######### Plot #########
% ########################
\begin{tikzpicture}
    \begin{axis}[
        myDefaultStyle,
        xmin = 0,
        xmax = 32,
        ymin = 24.5,
        ymax = 30.1,        
        xtick = {0,10,20,30},   
        ytick = {25,26,30},     
    ]
    % Plots 
    \addplot[domain=0:10,red]{x^2};     
    %   
    \end{axis}
\end{tikzpicture}

% ######### Plot #########
% ########################
\begin{tikzpicture}
    \begin{axis}[
        myDefaultStyle,
        xmin = 0,
        xmax = 32,
        ymin = 24.5,
        ymax = 30.1,        
        xtick = {0,10,20,30},   
        ytick = {25,26,30},     
        extra y ticks={25.5}, % <-- Added
    ]
    % Plots     
    \addplot[domain=0:10,red]{x^2}; 
    %
    \end{axis}
\end{tikzpicture}

\end{document}

With \pgfplotsset{compat=newest}

enter image description here

Without \pgfplotsset{compat=newest]

enter image description here

1 Answers1

2

As described in section 2.2.2 of the manual, it's possible to set the compat version for specific features, which are described in section 2.2.1, so for your case you can do

\pgfplotsset{
  compat=newest,
  compat/labels=default
}

to go back to the default setting for axis labels.

Addendum: Dos and Don'ts of \pgfplotsset{compat=newest}

Torbjørn T.
  • 206,688