# Problems with plotting planar functions with Tikz

I tried to plot this graph using tikz and pgfplots. The code compiled just fine, but I got a peculiar result that I can't explain. My code.

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xlabel=$x$,ylabel=$y$,
xmin=-6,xmax=6,ymin=-6,ymax=6, axis lines=center, axis equal]

\end{axis}
\end{tikzpicture}

\end{document}


This is the riddle I was presented with.

The shape my code produced (a line, strangely enough) perplexes me. I truly have no idea what I did wrong. Is there any internal process at fault? Can you please modify my code in such a way that the desired plot will actually show up? I'd be grateful if you (kind users who already mastered tikz and pgfplots) would help me. Thank you in advance.

• probably better to give the direct link to math.stackexchange.com/questions/713873/very-interesting-graph rather than rely on google search – David Carlisle Mar 30 '17 at 15:14
• I'm assuming you mean math.stackexchange.com/questions/713873/very-interesting-graph. You can't plot implicit functions directly in pgfplots like that. Try for example tex.stackexchange.com/questions/18359/… – Torbjørn T. Mar 30 '17 at 15:16
• I actually considered this, but at the end it isn't vital to the question. I will consider your suggestion again, though. Please help if you can. I'd like to observe the beauty of pgfplots. – Gregor Perčič Mar 30 '17 at 15:16
• Huh? What did you consider that you don't think is vital to the question? It is certainly vital that pgfplots cannot, as far as I know, plot implicit functions they way you're trying. – Torbjørn T. Mar 30 '17 at 17:28
• I considered putting the link directly to the Stack Exchange mathematics post and not simply to Google images not vital to my post, and NOT your information that states pgfplots can't do the desired work. I think you misunderstood me. – Gregor Perčič Mar 30 '17 at 17:32

I have seen this graph when I saw an introductory article on the small application GrafEq. The ideal behind is to compute the LHS and RHS using interval arithmetic. We cannot (at least it is pretty difficult to) do interval arithmetic in TeX. But we have the following for free

\documentclass[tikz]{standalone}

3 mul exch 3 mul exch % x y
2 copy                % x y x y
dup mul exch dup mul  % x y y² x²
add sin               % x y sin(x²+y²)
3 1 roll              % sin(x²+y²) x y
mul cos               % sin(x²+y²) cos(xy)
le                    % < or not <
{0 0 0}{1 1 1}ifelse  % black or white
}
3 mul exch 3 mul exch % x y
2 copy                % x y x y
dup mul exch dup mul  % x y y² x²
add sin               % x y sin(x²+y²)
3 1 roll              % sin(x²+y²) x y
mul cos               % sin(x²+y²) cos(xy)
sub dup mul           % (L-R)²
.01 le                % <.01 or not <.01
{0 0 0}{1 1 1}ifelse  % black or white
}

\begin{document}
\end{document}


# OR GNUPLOT

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90}]

• Um, thank you for your wonderful answer, I'm very grateful for it. Though I must say the result I got was not what you posted in your answer. Rather than getting a smooth plot, I have a bunch of pixels that kind of depict the general structure of the plot, but are utterly a mess. Can you help me with that? And also, I'd like to ask you to present an answer that can be attached to a mathematical paper (axis-like style). Thank you in advance. – Gregor Perčič Mar 30 '17 at 18:21
• I checked my produced PDF and it produces the expected result! Thank you so much (you get a tick for your effort :)). Though I would like to know how to plot such a graph with gnuplot and pgfplot. – Gregor Perčič Mar 30 '17 at 18:46
• Could you provide a link? There are multiple pgfplots manuals. – Gregor Perčič Mar 30 '17 at 19:04