下面的 LaTeX 代码生成
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{patterns, snakes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary {decorations.markings}
\begin{document}
\begin{tikzpicture}
\definecolor{fogr}{rgb}{0.13, 0.55, 0.13}
\begin{axis}[
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
axis lines = left,
domain = 0.5:4,
xmin=0,
ymin=0,
xmax = 5,
ymax=5,
label style={font=\tiny},
]
\plot[
smooth,
color=fogr,
thick,
bend right,
] {1.578051*x^-1.296597};
\end{axis}
\end{tikzpicture}
\end{document}
尝试在曲线上放置一个小箭头来指示方向。
已经尝试添加
\plot[
smooth,
color=fogr,
thick,
decoration={
markings,% switch on markings
mark=at position 1.75cm with {\node{\arrow[fogr]{stealth}}}},
postaction=decorate
]
{1.578051*x^-1.296597};
这将引发错误,因为Package pgf Error: I cannot decorate an empty path.
是否有任何简单的解决方案可以只绘制一个箭头,而不是先尝试保存 pgfplot 然后尝试在其上绘制。
答案1
使用
decoration={
markings,
mark=at position 0.5 with {\arrow[fogr]{stealth}}},
postaction=decorate
(没有\node
,并且相对位置为 0.5 而不是固定长度)。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{patterns, snakes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary {decorations.markings}
\begin{document}
\begin{tikzpicture}
\definecolor{fogr}{rgb}{0.13, 0.55, 0.13}
\begin{axis}[
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
axis lines = left,
domain = 0.5:4,
xmin=0,
ymin=0,
xmax = 5,
ymax=5,
label style={font=\tiny},
]
\plot[
smooth,
color=fogr,
thick,
bend right,
decoration={
markings,
mark=at position 0.5 with {\arrow[fogr]{stealth}}},
postaction=decorate
] {1.578051*x^-1.296597};
\end{axis}
\end{tikzpicture}
\end{document}