I would like to have the y axis labels of all plots in my document above the y axis line. Usually that is above origin
but sometimes I have to move the line out of the way. What I am looking for is a method to tie axis line and axis label together, so that they move as if they were one.
Attempt
The pgfplots manual (chapter 4.9.10 Moving Axis Lines) states that axis y line shift
allows to shift the axis line together with all its descriptions, but it does not seem to. The axis line moves but the label (which I consider a description of the axis line) stays in place. Even with ylabel shift
the label does not move.
Quick fix
As a substitute I currently move the axis line to the far left and align the label north west
. This is not really what I want but I can live with it.
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.17,
every axis/.style={
axis lines={center}, %%% axes at origin by default
every axis x label/.style={
at=(current axis.right of origin),
right,
},
every axis y label/.style={
at=(current axis.above origin), %%% y axis label above origin by default
above,
},
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ylabel={==y==},
axis y line shift={0.5}, %%% attempt: moves axis line (but not the label)
ylabel shift={0.5}, %%% attempt: has no effect
% axis y line={left}, %%% quick fix
% ylabel style={at=(current axis.north west)}, %%% quick fix
]
\addplot table {
-1 -1
1 1
};
\end{axis}
\end{tikzpicture}
\end{document}
The following image shows the output of the code above. The y label did not move with the y axis line. It is above the origin although it should have moved with the line.
The next image shows the result of the quick fix. Label '==y==' is above axis line.
every axis y label/.style={at=(yticklabel* cs:1), ...
work in all cases?