我有两个宽度不同的图并排在一起。我希望它们共享一个 x 轴标签。为此,我取左侧图的 x 轴标签并将其向右移动,使其完全位于组合图下方的中心。我使用
x label style={at={(axis description cs:1./2./0.7/0.95,-0.08)},anchor=north}
但是,由于 ,现在标签与 x 轴刻度标签的距离与所有其他图的距离都不同-0.08
。有什么方法可以获取默认值,这样我就不必用一些虚构的值来近似默认值了?
我发现以下 SE 问题有些相关:轴编号和轴标签之间的默认距离 pgfplots。这似乎2*inner sep + 2*outer sep = 2*0.3333em + 2*0.5\pgflinewidth
是默认距离。但我该如何将其转换为axis description cs
?
如果有更优雅的方式完成所有这些,请提及。我不必使用上述命令。
编辑1:示例代码
\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}
答案1
与 Harish Kumar 的解决方案不同,该解决方案使用xticklabel cs
坐标来放置额外的节点,而无需使用x label style
带有命令的宏xshift
。
代码
\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 (Harish Kumar's),
ylabel=Y-Label,
ymin=0.01,
ymax=1e11,
xmin=-0.5,
xmax=6.5,
scale only axis, clip=false,
x label style={at={(axis description cs:1./2./0.7/0.95,-0.08)},anchor=north},
x label style={xshift=0.8\textwidth*0.5-0.8\textwidth*0.7*0.95*0.5}
] % Harish Kumar's solution
\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;
\node[red] () at (xticklabel cs: 1,25pt) {This should be centered (Proposed)};
% adjust 20pt for variants
\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}