I'm working on this diagram:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (-0.1,-0.1) rectangle (5,3);
\draw[help lines,->] (0,0) -- (4.2,0);
\draw[help lines,->] (0,0) -- (0,3);% draw axis lines
\draw[gray,dashed] (0,2) -- (4.2,2); % draw asymptote
\draw[domain=0.1:4.6,very thick,red,->,samples=400] plot ({\x - 0.4},{1/(-\x) + 2} );% draw plot
\draw[help lines,->] (1,0) -- (1,1.2);
\draw[help lines,->] (2,0) -- (2,1.5);
\draw[help lines,->] (3,0) -- (3,1.65);
\draw[help lines,->] (4,0) -- (4,1.7);
% scale to fit marginfigure
\end{tikzpicture}
\end{document}
It gets the job done, more or less, but I'm wondering whether there's a cleaner or more elegant way to do it. Specifically, I'm wondering:
-
Is there a way to draw the curved line as a ray with an endpoint at (0,0)? The problem with drawing a demihyperbola and then clipping is that I want to label several points on that path (which is what the vertical arrows are for). I can't do that if I have to clip the diagram so closely.
-
Is there a way to describe the height of the vertical lines as relative to the curved plot (i.e., can I tell
tikz
, "Draw a vertical line, with an arrowhead, from (1,0) until it intersects the curved line")?
Best Answer
If I understand correctly, this is what you're asking for:
Using the
tikzlibrary
calc
allows you to take into account the thickness of the red curve (hence the offset of0.6pt
).You could write a macro to handle the y-coordinate: