2

I'm learning how to use gnuplot with TikZ.

I would like to draw next one to each other graphs of some algebraic curves. I'm starting with graphs that can be drawn without gnuplot (they are not implicit). I would like to draw next to them an implicit curve with the same style (same axis, centered and ultra thick).

Here is what I have achieved so far.

\documentclass{standalone}

\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\usepackage[shell]{gnuplottex}
\thispagestyle{empty}

\begin{document}

\begin{tikzpicture}
\def\sizeGraph{1.3}

  \draw[domain=-0.91:0.91, smooth, variable=\x, red, ultra thick] plot ({\x}, {sqrt(1-\x*\x)});
  \draw[domain=-1:-0.9, smooth, variable=\x, red, ultra thick] plot ({\x}, {sqrt(1-\x*\x)});
  \draw[domain=0.9:1, smooth, variable=\x, red, ultra thick] plot ({\x}, {sqrt(1-\x*\x)});

  \draw[domain=-0.91:0.91, smooth, variable=\x, red, ultra thick] plot ({\x}, {-sqrt(1-\x*\x)});
  \draw[domain=-1:-0.9, smooth, variable=\x, red, ultra thick] plot ({\x}, {-sqrt(1-\x*\x)});
  \draw[domain=0.9:1, smooth, variable=\x, red, ultra thick] plot ({\x}, {-sqrt(1-\x*\x)});

  \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
  \draw[->] (0,-\sizeGraph) -- (0,\sizeGraph) node[above] {$y$};
  
  \node [below=1.5cm, align=flush center]
        {
            $V(X^2+Y^2-1)$
        };
\end{tikzpicture}
\qquad
\begin{tikzpicture}
\def\sizeGraph{1.3}

    \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth, variable=\x, blue, ultra thick] plot ({\x}, {\x*\x});
    \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
    \draw[->] (0,-1.3) -- (0,1.3) node[above] {$y$};
    
      \node [below=1.5cm, align=flush center]
        {
            $V(Y-X^2)$
        };
\end{tikzpicture}
\qquad
\begin{tikzpicture}
\def\sizeGraph{1.3}

    \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth, variable=\x, orange!60!black, ultra thick] plot ({\x}, {\x});
    \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth, variable=\x, orange!60!black, ultra thick] plot ({\x}, {-\x});
    \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
    \draw[->] (0,-1.3) -- (0,1.3) node[above] {$y$};
    
      \node [below=1.5cm, align=flush center]
        {
            $V(Y^2-X^2)$
        };
\end{tikzpicture}
\quad
\begin{tikzpicture}
\def\sizeGraph{1.3}
    
    \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
    \draw[->] (0,-1.3) -- (0,1.3) node[above] {$y$};
    
    \begin{gnuplot}[terminal=tikz,terminaloptions={size 8,8}]
      set contour
      set cntrparam levels incremental 0.0001, 0.0001, 0.0001
      set view map
      set view equal
      unset surface
      unset key
      unset tics
      unset border
      set lmargin at screen 0
      set rmargin at screen 1
      set bmargin at screen 0
      set tmargin at screen 1
      set isosamples 1000,1000
      set xrange [-3.5:3.5]
      set yrange [-3.5:3.5]
      set view 0,0
      set cont base
      splot x**3 + y**3 - 6*x*y
    \end{gnuplot}
  \end{tikzpicture}

\end{document}

enter image description here

Can you help me?

7
  • I had this one mistake: LaTeX Error: File gnuplot-lua-tikz.sty' not found.` Where did you get this package?
    – AndréC
    Aug 11, 2020 at 12:52
  • Thanks for your help. I'm a bit struggling with gnuplot. I got it there: overleaf.com/latex/examples/example-gnuplot-plus-tikz/…
    – Colas
    Aug 11, 2020 at 12:59
  • 1
    The use of gnuplot in TikZ is explained at pag.344 of the pfgmanual ver.3.1.5b
    – vi pa
    Aug 13, 2020 at 10:45
  • @AndréC gnuplot-lua-tikz ships with gnuplot. Aug 14, 2020 at 5:35
  • 1
    @AndréC I don't use MikTeX, sorry, but what should always work is just copying the file to the working directory. Aug 14, 2020 at 5:57

1 Answer 1

4
+25

I propose the solution below which does not use gnuplot. I hope you are not unconditionally in love with it.

enter image description here

It uses TikZ only and a parametrization of the singular cubic.

The parametrization is obtained by projecting the curve from the origin onto the line x+y=1. We get (x, y) = 6t/(1+t^3)(1, t).

We have to make some choices during the drawing process since t is different from -1. This is the reason for the four \draw commands. They might be transformed into two though.

Your axes are too small for the coefficient 6 in the cubic's equation. So, I scaled down the curve to fit the interesting part in the desired rectangle.

\documentclass[11pt, border=.5cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc, math}

\begin{document}

\tikzmath{%
  real \sizeGraph;
  \sizeGraph = 1.4;
}
\begin{tikzpicture}  
  \draw[domain=-0.91:0.91, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {sqrt(1-\x*\x)});
  \draw[domain=-1:-0.9, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {sqrt(1-\x*\x)});
  \draw[domain=0.9:1, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {sqrt(1-\x*\x)});

  \draw[domain=-0.91:0.91, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {-sqrt(1-\x*\x)});
  \draw[domain=-1:-0.9, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {-sqrt(1-\x*\x)});
  \draw[domain=0.9:1, smooth, variable=\x, red, ultra thick]
  plot ({\x}, {-sqrt(1-\x*\x)});
  \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
  \draw[->] (0,-\sizeGraph) -- (0,\sizeGraph) node[above] {$y$};
  
  \node[below=1.5cm, align=flush center] {$V(X^2+Y^2-1)$};
\end{tikzpicture}
\qquad
\begin{tikzpicture}
  \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth,
  variable=\x, blue, ultra thick] plot ({\x}, {\x*\x});
  \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
  \draw[->] (0,-\sizeGraph) -- (0,\sizeGraph) node[above] {$y$};
    
  \node [below=1.5cm, align=flush center]{$V(Y-X^2)$};
\end{tikzpicture}
\qquad
\begin{tikzpicture}
  \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth,
  variable=\x, orange!60!black, ultra thick] plot ({\x}, {\x});
  \draw[samples=1000, domain=-\sizeGraph:\sizeGraph, smooth,
  variable=\x, orange!60!black, ultra thick] plot ({\x}, {-\x});
  \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
  \draw[->] (0,-\sizeGraph) -- (0,\sizeGraph) node[above] {$y$};
  
  \node [below=1.5cm, align=flush center] {$V(Y^2-X^2)$};
\end{tikzpicture}
\quad
\tikzmath{%
  integer \N{-}, \N{+}, \j;
  \N{-} = 21;
  \N{+} = 22;
}
\begin{tikzpicture}
  \begin{scope}[red, ultra thick, scale=.4]
    \draw (0, 0)
    \foreach \i [evaluate=\i as \j using \i/20] in {1, ..., \N{+}}{%
      -- (${1/(1+\j^3)*(6*\j)}*(1, \j)$)
    };
    \draw (0, 0)
    \foreach \i [evaluate=\i as \j using -\i/40] in {1, ..., \N{-}}{%
      -- (${6*\j/(1+\j^3)}*(1, \j)$)
    };
    
    \draw (0, 0)
    \foreach \i [evaluate=\i as \j using \i/20] in {1, ..., \N{+}}{%
      -- (${1/(1+\j^3)*(6*\j)}*(\j, 1)$)
    };
    \draw (0, 0)
    \foreach \i [evaluate=\i as \j using -\i/40] in {1, ..., \N{-}}{%
      -- (${6*\j/(1+\j^3)}*(\j, 1)$)
    };  
  \end{scope}
    \draw[->] (-\sizeGraph,0) -- (\sizeGraph,0) node[right] {$x$};
  \draw[->] (0,-\sizeGraph) -- (0,\sizeGraph) node[above] {$y$};

  \node [below=1.5cm, align=flush center] {$V(X^3+Y^3-6XY)$};
\end{tikzpicture}

\end{document}
1
  • Thanks. I was looking for a solution without parametrisation but in the end, I had to change my mind.
    – Colas
    Sep 6, 2020 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .