I want to draw the following diagram

enter image description here

Here is my MWE with (ps-tricks)

\usepackage{pst-plot, pst-node}

\psset{algebraic=true, arrowsize=3pt,arrowinset=0.15, plotpoints=500, linecolor=LightSteelBlue3}
    \psaxes[ticks=none, labels=none, arrows=->](0,0)(-3,-4)(8,4.5)[$x$, -110][$y$,-135]
    \parametricplot[linecolor =IndianRed3, linewidth=1.2pt]{-4}{4}{t^2| t}
    \dotnode[linecolor =IndianRed3](1, 4){S}\pnodes(2,2){Sx}(1,4){Sy}
    \psset{linewidth = 0.4pt, linestyle=dashed}


Just for variety, here's a pgfplots solution

enter image description here

% arara: pdflatex

% graphs

% axis style
    every axis/.append style={
            axis x line=middle,
            axis y line=middle,
            axis line style={->},
    soldot/.style={color=green,only marks,mark=*},
    holdot/.style={color=green,fill=white,only marks,mark=*},
    grid style={dotted,gray},

% arrow style


            axis equal,
        \addplot[soldot]coordinates {(2,2)} node [anchor=north west,text=black]  {$(x,y)$};
        \addplot[soldot,red]coordinates {(1,4)} node [anchor=south west,text=black]  {$(1,4)$};
        \draw [red, dashed](axis cs: 2,2) -- (axis cs: 1,4) node [pos=0.5,anchor=north east]{$d$};


The function is y=\sqrt(2x) which is x=(tˆ2)/2, y=t

\usepackage{pst-plot, pst-node}

\psset{algebraic=true,plotpoints=500, linecolor=LightSteelBlue3}
    \psaxes[ticks=none, labels=none, arrows=->](0,0)(-3,-4)(8,4.5)[$x$, -110][$y$,-135]
    \parametricplot[linecolor=IndianRed3, linewidth=1.2pt]{-4}{4}{t^2/2| t}
    \psdot[linecolor =IndianRed3](1,4)\psdot[linecolor=green](2,2)


enter image description here


Here's a version using tikz



  \draw[black, ultra thick, ->] (0, -4) -- (0, 4) node[left]{$y$};
  \draw[black, ultra thick, ->] (-0.5, 0) -- (4, 0) node[below]{$x$};
  \draw[dotted] (-0.5, -4) grid (4, 4);

  \draw[black, line width = 1mm, green!80!blue]   plot[smooth, domain=-sqrt(8):sqrt(8)] (0.5 * \x * \x, \x);
  \fill[green!80!blue] (2, 2) circle (0.2) node[below, outer sep = 5pt, black]{$(x, y)$};
  \fill[red] (1, 4) circle (0.2) node[right, outer sep = 5pt, black]{$(1, 4)$};
  \draw[red, dashed, thick] (1, 4) -- (2, 2) node[midway, left, outer sep = 5pt]{$d$};

  \foreach \x in {1, 2, 3} \node[below] at (\x, 0){$\x$};
  \foreach \y in {0, 1} \node[left] at (0, \y){$\y$};


enter image description here


It can also be done with MetaPost. I chose to draw it with strokes less thick than in the OP's graph, I think it looks better like that.

Code included in a LuaLaTeX program for typesetting convenience.

\usepackage{luatex85, luamplib}
u := cm; xmin = -.5; xmax = 4; ystep := .1; ymax = -ymin = 4;
vardef f(expr y) = .5(y**2) enddef;
picture curve; color thisgreen; thisgreen = .5[green,black];
    % grid
    for x = ceiling(xmin) upto xmax:
        draw ((x, ymin) -- (x, ymax)) scaled u dashed withdots;
        if (x >=1) and (x<=3): label.llft("$" & decimal x & "$", (x*u, 0)); fi
    for y = ymin upto ymax:
        draw ((xmin, y) -- (xmax, y)) scaled u dashed withdots;
    % Axes
    drawarrow (xmin*u, 0) -- (xmax*u, 0);
    label.llft("$0$", origin); label.bot("$x$", (xmax*u, 0));
    drawarrow (0, ymin*u) -- (0, ymax*u);
    label.ulft("$y$", (0, ymax*u)); label.llft("$1$", (0, u));
    % parabola
    curve = image(draw ((f(ymin), ymin)
        for y = ymin+ystep step ystep until ymax+.5ystep: .. (f(y), y) endfor) 
            scaled u withcolor thisgreen);
    clip curve to 
        ((xmin, ymin) -- (xmax, ymin) -- (xmax, ymax) -- (xmin, ymax) -- cycle)
            scaled u; draw curve;
    % Distance
    label.top("$(1, 4)$", u*(1, 4)); label.lrt("$(x, y)$", u*(2, 2));
    drawoptions (withcolor red);
    z1 = u*(1, 4); z2 = u*(2, 2); draw z1 -- z2 dashed evenly;
    label.llft("$d$", .5[z1,z2]);
    pickup pencircle scaled 3bp;
    drawdot z1; drawdot z2 withcolor thisgreen;

enter image description here


An optimized PSTricks solution only for emergency purpose.

    xticksize=-4 5,
    yticksize=-1 6,

enter image description here


You could also just recycle an answer to a previous question of yours. The plot can be obtained by reflecting the function y=x^2/2 about the 45-degree line.


\begin{tikzpicture}[%from https://tex.stackexchange.com/a/401669/121799
declare function={ f(\x)                 = \x^2/2; 
                   reflectedx(\x)        = -\x+2*\mya*(\x*\mya+f(\x)*\myb)/(pow(\mya,2)+pow(\myb,2));
                   reflectedy(\x)        = -f(\x)+2*\myb*(\x*\mya+f(\x)*\myb)/(pow(\mya,2)+pow(\myb,2));
\addplot [samples=50, blue,ultra thick] ({reflectedx(x)}, {reflectedy(x)});

enter image description here


All the previous answers (PSTricks, MetaPost, TikZ) use a plot to draw the parabola. So they use a lot of segments to approximate it.

In the spirit of this answer I want to advocate to use a single quadratic (cubic) curve to draw the exact parabola.

Here is a TikZ solution that can be adapted to PSTricks and MetaPost, but as I'm not comfortable with this two, I make this answer to a wiki in a way that somebody can add the other two languages.

We can directly draw the curve as (4.5,3) .. controls (-1.5,1) and (-1.5,-1) .. (4.5,-3) or we can scale a "standard" one (1,1) .. controls (-1/3,1/3) and (-1/3,-1/3) .. (1,-1) that draws y->y^2 over [-1,1].

    % clip control points that are outside
    \clip (-.5,-4) rectangle (4.5,4);
    % draw the grid
    \draw[help lines] (-.5,-4) grid (4.5,4);
    % direct draw of y->y^2/2 over [-3,3]
    \draw[ultra thick,red]
      (4.5,3) .. controls (-1.5,1) and (-1.5,-1) .. (4.5,-3);
    % draw of y->y^2 over [-1,1] and scale it by (3^2/2,3)
    \draw[thick, white, yscale=3, xscale=3^2/2]
      (1,1) .. controls (-1/3,1/3) and (-1/3,-1/3) .. (1,-1);

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.