在 PGFPlots 中,我想将非方框轴的默认轴描述位置设置在箭头附近,否则保留现有默认设置,即将轴描述放置在轴两端中间。例如,请看以下代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{%
every axis x label/.style={%
at={(ticklabel cs:0.95)}, anchor=near ticklabel,
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
axis x line=bottom,
axis y line=left,
]
\addplot[
domain=-2:2,
samples=100,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
生成结果:
every axis x label
无论轴是带框的还是非带框的,都会设置轴描述位置(注释掉即可axis x line
看到)。有一个every non boxed x axis
键,但我认为这是针对轴线的,而不是描述的。我找不到键every non boxed axis x label
或类似的东西。当然,我可以根据具体情况来做这件事(我一直在这样做),但我更愿意将其设为默认值。这可能吗?
答案1
我认为如果你把every axis x label
样式放在里面,它就会起作用。如果你想的话,也可以every non boxed x axis
把它复制进去。every non boxed y axis
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{%
every non boxed x axis/.style={
every axis x label/.style={%
at={(ticklabel cs:0.95)}, anchor=near ticklabel,
},
},
every non boxed y axis/.style={
every axis x label/.style={%
at={(ticklabel cs:0.95)}, anchor=near ticklabel,
},
},
width=7cm, height=3cm % just for example
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
axis x line=bottom,
axis y line=left,
]
\addplot[
domain=-2:2,
samples=100,
] {x^2};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
]
\addplot[
domain=-2:2,
samples=100,
] {x^2};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
axis y line=left,
]
\addplot[
domain=-2:2,
samples=100,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}