-1

I would like to plot a lemniscate Bernoulli (2D) in Latex and in polar coordinates, but I haven’t the appropriate code. Probably it would be easier to plot that in Octave or gnuplot, but I have a pressing time. Any help ?

1 Answers1

3

Here is the code you need

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.10}
\pgfdeclarelayer{bg}    
\pgfsetlayers{bg,main}

\begin{document}

\begin{tikzpicture} \begin{polaraxis}[style=black!10,grid style=black!10,ticklabel style=black!50,xticklabel=$\pgfmathprintnumber{\tick}^\circ$ ] \addplot [name path=A,thick, blue, domain=0:45, samples=50] {2sqrt(cos(2x))}; \addplot [thick, red, domain=-45:0, samples=50] {2sqrt(cos(2x))}; \addplot [thick, red, domain=135:225, samples=100] {2sqrt(cos(2x))}; \draw [name path=B,blue,thick,opacity=.5,dotted] (0:0) -- (0:201); \tikzfillbetween[on layer=bg,of=A and B]{gray!50} \end{polaraxis} \end{tikzpicture}

\end{document}

which provides

enter image description here

brad
  • 517
  • The solution is superb. It works perfect. Thank you a lot. Now, I have due to symmetry to shade a quarter of the plot in order to calculate the whole lemniscate. The shading in Latex should be according to this information: https://tex.stackexchange.com/questions/407148/shading-a-part-of-a-plot – Spyridon Kanavos Jan 13 '22 at 08:47
  • Try changing \addplot [thick, red, domain=-45:45, samples=100] {2*sqrt(cos(2*x))}; into \addplot [thick, red, domain=-45:0, samples=50] {2*sqrt(cos(2*x))}; \addplot [thick, blue, domain=0:45, samples=50] {2*sqrt(cos(2*x))};
    Does this suit your needs?
    – brad Jan 13 '22 at 11:35
  • Or do you mean that you want the inside area shaded? – brad Jan 13 '22 at 11:46
  • I will shade inside the quarter of the whole area of the lemniscate, which is at the first quadrant of the circle with boarders y = 0, x: [0, 2] and the upper line of the function's curve. – Spyridon Kanavos Jan 13 '22 at 12:19
  • I have edited the code to suit your needs – brad Jan 13 '22 at 15:24
  • Excellent. It works perfect! Thank you so much for your help. Your help is invaluable. I write books in Mathematics and until now I used other command-line and GUI programs that can generate two- and three-dimensional plots of functions, like gnuplot or CAS like Sage etc. Lastly, I use PS Tricks Latex, for direct insertion of figures in the text. Thanks to the scientific community of this website, I have solved many problems. – Spyridon Kanavos Jan 14 '22 at 08:24
  • @SpyridonKanavos You might be interested in https://tex.stackexchange.com/help/accepted-answer – samcarter_is_at_topanswers.xyz Oct 13 '22 at 10:24