I want to draw a similar image to the one below. Is it possible to do this in TikZ?
-
1Have you started a minimal working example? if yes please provide it to help the people willing to help you, so they don't start from scratch. there is more chance someone helps you if you give a start. – Cfun Jul 07 '16 at 20:18
-
1See also my answer to Draw arrows from axis to curve. – Alenanno Jul 07 '16 at 20:44
-
@Alenanno, in my stock of interesting answers on SX I have answer, foe which I forgot to make note where is original ... Now I will complete it with this data. My answer is based on it ... – Zarko Jul 07 '16 at 21:22
3 Answers
As starting point:
\documentclass[tikz,
border=3mm,
]{standalone}
\usetikzlibrary{arrows.meta,
intersections,
}
\begin{document}
\begin{tikzpicture}
\draw[->] (-0.1, 0) -- (3,0) node[below left] {$x$};
\draw[->] (0, -0.1) -- (0,4) node[below left] {$y$};
%
\draw[name path=A,
red, very thick] (0,0) .. controls +(2,1) and +(0,-1) .. (2,4);
\foreach \i [count=\ix] in {0.5,1,...,3.5}
{
\path[name path=B\ix] (0,\i) -- + (3,0);
\draw[name intersections={of=A and B\ix, by={a}}];
\draw[thick,-{Triangle[]}] (0,\i) -- (a);
}
\end{tikzpicture}
\end{document}
Draw of dashed line I left you ...
- 296,517
In plain Metapost there are two macros, called cutbefore and cutafter, that help with this type of drawing.
This is produced from:
prologues := 3;
outputtemplate := "%j%c.eps";
beginfig(1);
numeric u;
u = 1cm;
path xx, yy, ff;
xx = (left--3 right) scaled u;
yy = (origin--4 up) scaled u;
ff = origin .. {up} (2.5u,4u);
draw ff withcolor .67 red;
for t=1 upto 8:
drawarrow xx shifted (0,1/2t*u)
cutbefore yy
cutafter ff;
endfor
draw xx;
draw yy;
endfig;
end.
To draw the arrows, I've reused the xx path created for the x-axis. At each step in the loop, it's shifted up, and cut off at the y-axis and the curve before being drawn.
Additional notes
Plain Metapost defines left to be (-1,0), right to be (1,0), up as (0,1) and down as (0,-1). I find that I get less confused when I write 4 up instead of (0,4).
I've drawn the ff curve first, so that the arrow tips are on top of it. This looks better than if they are underneath it. But for a more professional job it would be better to shorten the arrows slightly. You can do this my moving the line that cuts them off a little bit to the left. So if you replace
cutafter ff;
with
cutafter ff shifted 2/3 left;
you get this slightly neater result:
- 42,268
A PSTricks solution.
\documentclass{article}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-0.2,-0.2)(2.2,4.5)
\psaxes[
labels = none,
ticks = none
]{->}(0,0)(-0.2,-0.2)(2.2,4.5)
\psplot[
linecolor = red
]{0}{2.1}{x dup mul}
\multido{\r = 0.4+0.4}{10}{\psline{->}(0,\r)(!\r\space sqrt \r\space)}
\end{pspicture}
\end{document}
Notice that \r\space sqrt (sqrt(\r) in PostScript notation) is the inverse function of x dup mul (x^2 in PostScript notation).
- 31,033




