I am trying to plot the elliptic curve secp256k1 y^2=x^3+7 in my latex-document.

\begin{tikzpicture}[domain=-4:4, samples at ={-1.769292354238631, -1.76, -1.74, ..., 2.26, 2.35, 2.7, 2.9}]
    \draw[->] (-2.2,0) -- (3.2,0) node[right] {$x$};
    \draw[->] (0,-2.2) -- (0,4.2) node[above] {$y$};
    \draw[->, color=red] plot (\x,{sqrt(\x^3+7)}) node[right] {$y^2=x^3-2x+2$};
    \draw[->, color=red] plot (\x,{-sqrt(\x^3+7)}) node[right] {}

but this gives me a curve that is interrupted at the left. And to be honest, I don't really know what all of these comments mean.

I would be happy if someone could help me, or has a good tutorial that explains how the plotting in Latex works!

Thanks in advance! And all the best.


Here is a solution that really uses PGFPlots. There you would get a very similar result as you did, when you wouldn't set the minimum x value (of the domain) manually.

            scale only axis,
            axis lines=middle,
            % set the minimum value to the minimum x value
            % which in this case is $-\sqrt[3]{7}$
            domain=-1.912931:3,      % <-- works for pdfLaTeX and LuaLaTeX
%            domain=-1.91293118:3,   % <-- would also work for LuaLaTeX
            % to avoid that the "plot node" is clipped (partially)
            % use same unit vectors on the axis
            axis equal image=true,
            \addplot [red] {sqrt(x^3+7)}
                node[right] {$y^2=x^3+7$};
            \addplot [red] {-sqrt(x^3+7)};

image showing the result of above code

  • 1
    I'm not sure the picture is right. – egreg Nov 26 '16 at 22:28
  • @egreg, I think you skepticism came from the scaling of the axis. I edited my answer to use the same unit vector on both axis. – Stefan Pinnow Nov 27 '16 at 7:16
  • It wasn't the plot of y^2 = x because it was clipped. – percusse Nov 27 '16 at 9:20
  • @StefanPinnow The equation of the curve was wrongly printed – egreg Nov 27 '16 at 9:21
  • @egreg, sorry, I think I don't understand your point. When you agree that the actual image is right, then also the "old" one was right, because the only (important) thing I changed was adding the option axis equal image=true. So when you comment that line or set the value to false you will get the "old" image (again) ... – Stefan Pinnow Nov 27 '16 at 9:27

If you have no objection using pstricks, it's very simple to plot:

\documentclass[11pt,x11names, border=3pt]{standalone}


\def\f{sqrt(x^3 + 7)}


\psset{plotpoints=200, plotstyle=curve, algebraic, arrowinset=0.12}%
    \psaxes[linecolor=LightSteelBlue3, tickcolor=LightSteelBlue3, ticksize=-2pt 2pt, labels =none, arrows=->, ](0,0)(-5.8,-6.5)(6,7)[$x$, -120][$y$, -135]
    \uput[dl](0,0){$ O $}\uput[dl](-1.913,0){ $ -\sqrt[3]{7} $}
    \uput[dl](0,-2.65 ){$ -\sqrt{7}$} \uput[ul](0,2.65 ){$ \sqrt{7}$}
    \psset{linewidth=1.5pt, linecolor=IndianRed3}


enter image description here

Note: This code is compilable with pdflatex if you launch it with the -shell-escape switch (under TeX Live or MacTeX), or --enable-write18 (MiKTeX). Alternatively, remove the auto-pst-pdf package, and compile with xelatex.


Plotted as y^2-x^3-7=0. Run with xelatex

\documentclass[11pt,x11names, border=3pt]{standalone}

\psaxes[labels=none,arrows=->,linecolor=black!50](0,0)(-3,-6.5)(6,7)[$x$, -120][$y$,-135]
\uput[dl](0,0){$ O $}\uput[dl](-1.913,0){ $ -\sqrt[3]{7} $}
\uput[dl](0,-2.65 ){$ -\sqrt{7}$} \uput[ul](0,2.65 ){$ \sqrt{7}$}
\psplotImp[linewidth=2pt,linecolor=red!60,algebraic](-4,-8)(6,8){y^2 - x^3 - 7}


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.