As in thread Get the auto generated tick distance of a pgfplot (DIN 461) already asked, i am searching for a way to get the units between last two ticks. The solution from the mentioned thread works for one axis. I tried to extend the code for two axes, but this only works for on axis. What am I doing wrong?
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{siunitx}
\pgfplotsset{
din xunit/.style={
xticklabel style={
name=xlabel\ticknum,
append after command=\pgfextra{\xdef\lastxticknum{\ticknum}}
},
after end axis/.code={
\pgfmathparse{int(\lastxticknum-1)}
\path (xlabel\lastxticknum.base) -- (xlabel\pgfmathresult.base) node [midway, anchor=base] {#1};
}
},
din yunit/.style={
yticklabel style={
name=ylabel\ticknum,
append after command=\pgfextra{\xdef\lastyticknum{\ticknum}}
},
after end axis/.code={
\pgfmathparse{int(\lastyticknum-1)}
\path (ylabel\lastyticknum.base) -- (ylabel\pgfmathresult.base) node [midway, anchor=base] {#1};
}
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[din xunit=\si{\second}, din yunit=\si{\meter}]
\addplot table {
0 0
1 3
2 4
};
\end{axis}
\end{tikzpicture}
\end{document}

