调整 pgfplots 中标签和轴之间的距离

调整 pgfplots 中标签和轴之间的距离

以下绘图的单个标签与曲线相交。我怎样才能使它离轴稍远一点并用虚线指向轴?

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
minor tick num=1,
axis x line=middle,
axis y line=left,
yticklabels={,},
xticklabels={$s$},
xtick=1,
ytick=\empty,
]
\addplot[blue,domain=0:20] {((x)/(x+1))-0.5};
\end{axis}
\end{tikzpicture}
\end{document}

答案1

您可以append after commandxticklabel style选项中使用插入绘图命令:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=left,
tickwidth=0pt,
xticklabels={$s$},
xticklabel style={
    yshift=-3ex,
    name=label,
    append after command={(label.north) edge [densely dashed] ++(0,3ex)}},
xtick=1,
ytick=\empty,
]
\addplot[blue,domain=0:20, smooth] {((x)/(x+1))-0.5};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容