I have two plots of different width next to each other. I want them to share one x-axis label. For this I take the x-axis label of the left plot and shift it to the right so that it is perfectly centred below the combined graph. I do this using
x label style={at={(axis description cs:1./2./0.7/0.95,-0.08)},anchor=north}
However, now the label has a different distance to the x-axis tick labels than in all other plots due to the -0.08
. Is there any way I can get a default value so that I do not have to approximate the default by some made up value?
I found the following SE question that is somewhat related: Default distance between axis numbers and axis labels pgfplots. It seems 2*inner sep + 2*outer sep = 2*0.3333em + 2*0.5\pgflinewidth
is the default distance. But how do I translate this into the axis description cs
?
If there is a more elegant way of doing all of this please mention it. I am not bound to use the above command.
Edit 1: Sample code
\documentclass[]{scrartcl}
\usepackage{pgfplots,pgfplotstable,tikz}
\pgfplotsset{compat=1.9}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\pgfplotsset{
myaxis/.style={
width=0.8\textwidth*0.7*0.95,
height=0.8\textwidth/1.61803398875,
}
}
%
\begin{semilogyaxis}[
myaxis,
xlabel=This should be centered,
ylabel=Y-Label,
ymin=0.01,
ymax=1e11,
xmin=-0.5,
xmax=6.5,
scale only axis,
x label style={at={(axis description cs:1./2./0.7/0.95,-0.08)},anchor=north},
] %
\draw
(axis cs:3.5,0.13)coordinate(ul)--
(axis cs:6.5,0.13)coordinate(ur)--
(axis cs:6.5,1.6)coordinate(or)--
(axis cs:3.5,1.6) -- cycle;
\end{semilogyaxis} %
\begin{axis}[
myaxis,
xshift=0.8\textwidth*0.7+0.8\textwidth*0.3*0.05,
width=0.8\textwidth*0.3*0.95,
xmin=3.5,
minor y tick num = 4,
xmax=6.5,
ymin=0.13,
ymax=1.6,
restrict y to domain=0.13:1.6,
restrict x to domain=3.5:6.5,
%trim axis left,
yticklabel pos=right,
scale only axis,
]
\end{axis}
\draw
(current axis.north west)--(or)
(current axis.south west)--(ur);
\end{tikzpicture} %
\end{figure}
\end{document}
Best Answer
Different from Harish Kumar's solution, this solution uses
xticklabel cs
coordinate to place an extra node without usingx label style
macro withxshift
command.Code