我已经创建了一个 tikz 图,现在我想在其上绘制箭头以显示流向。当前使用的代码是:
\begin{tikzpicture}
\draw[thick, ->] (0, -3) -- (0, 3) node [black, anchor=south] {$y$};
\draw[thick, ->] (-3, 0) -- (3, 0) node [black, anchor=west] {$x$};
\draw[scale=1,domain=0.33:3,smooth,variable=\x,black, thick] plot ({\x},{1/\x});
\draw[scale=1,domain=-3:-0.33,smooth,variable=\x,black, thick] plot ({\x},{1/\x});
\draw[scale=1,domain=0.33:3,smooth,variable=\x,black, thick] plot ({\x},{-1/\x});
\draw[scale=1,domain=-3:-0.33,smooth,variable=\x,black, thick] plot ({\x},{-1/\x});
\end{tikzpicture}
产生图像
现在我想在每条线上分别添加箭头。我需要给出箭头的方向(在这种情况下,我想在另一个示例中使用它)。它们应该出现在曲线的大约一半处。例如:
答案1
像这样吗?
\documentclass[border=3mm,
tikz,
preview
]{standalone}
\usetikzlibrary{decorations.markings,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\begin{scope}[decoration={markings,
mark=at position 0.25 with {\arrow[blue,very thick]{>}},
mark=at position 0.75 with {\arrowreversed[blue,very thick]{>}}}
]
\draw[postaction={decorate},thick,->] (0, -3) -- (0,3) node [black,above] {$y$};
\end{scope}
\begin{scope}[decoration={markings,
mark=at position 0.25 with {\arrowreversed[blue,very thick]{>}},
mark=at position 0.75 with {\arrow[blue,very thick]{>}}}
]
\draw[postaction={decorate},thick,->] (-3, 0) -- (3,0) node [black,right] {$x$};
\end{scope}
\begin{scope}[decoration={markings,
mark=at position 22mm with {\arrow[red,very thick]{>}}}
]
\draw[postaction={decorate},thick] plot[domain=0.33:3] (\x,{1/\x});
\draw[postaction={decorate},thick] plot[domain=-0.33:-3] ({\x},{1/\x});
\draw[postaction={decorate},thick] plot[domain=0.33:3] (\x,{-1/\x});
\draw[postaction={decorate},thick] plot[domain=-0.33:-3] (\x,{-1/\x});
\end{scope}
\end{tikzpicture}
\end{document}
编辑:第一次尝试时,我还没有考虑箭头的方向,也没有将它们添加到坐标轴上。现在这个问题已经纠正了。为了获得不同方向的箭头,我scope
为每个坐标轴和曲线分别定义装饰。为此,我反转了其中两个域,使箭头的方向正确。