0

I want to plot an equation, not a function, with TikZ. Is there any general way to realize it without calculation?

For example to plot the equation: 2x²-2xy+2y²=1 as follows

enter image description here

3
  • Place a \node, e.g. at (1.5, 0.4), and enter text in math mode, like \node at (1.5, 0.4) {$2 x^2 ...$}; . That should do the job.
    – MS-SPO
    Commented Jun 12, 2022 at 10:52
  • 1
    The pedestrian way: find the corresponding function, e.g. in wolframalpha.com 2x^2 - 2xy + 2y^2 = 1; solve (y): y = 1/2 (x - sqrt(2 - 3 x^2)), y = 1/2 (x + sqrt(2 - 3 x^2)) Commented Jun 12, 2022 at 11:09
  • 1
    ...or you can use the plotting of implicit function through gnuplot: tex.stackexchange.com/questions/18359/…
    – Rmano
    Commented Jun 12, 2022 at 11:18

1 Answer 1

0

This (standing on the shoulder of giants) works. There is a warning Missing character: There is no ` in font nullfont! which I do not like at all, but I am not sure where it comes from.

You must compile with -shell-escape and have a recent gnuplot installed and reachable in your standard PATH.

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
      grid,
      xmin = -1, xmax=3,
      ymin=-1, ymax=1,
      ]
    \addplot +[no markers,
      raw gnuplot,
      thick,
      empty line = jump %
      ] gnuplot {
      set xrange[-1:3];
      set contour base;
      set cntrparam levels discrete 0.0;
      unset surface;
      set view map;
      set isosamples 500;
      splot 2*x*x-2*x*y+2*y*y-1;
    };
  \path (1,0.5) node[right, fill=white]{$2x^2-2xy+2y^2=1$};
  \end{axis}
\end{tikzpicture}
\end{document}

implicit function plot through gnuplot

1
  • Thank you so much!
    – Ben
    Commented Jun 12, 2022 at 20:11

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