I have been trying to plot a couple of really simple implicit linear functions using only pgfplots internal facilities.
Here is my MWE:
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\pgfplotsset{compat=newest}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{3*x + 2*y - 2};
\end{axis}
\end{tikzpicture}
\end{document}
When I run this, I get this error:
! Package pgfplots Error: Sorry, you can't use 'y' in this context. PGFPlots ex
pected to sample a line, not a mesh. Please use the [mesh] option combined with
[samples y>0] and [domain y!=0:0] to indicate a twodimensional input domain.
See the pgfplots package documentation for explanation.
This particular function can be made explicit, but I'd still like to know if it is possible to plot implicit functions with pure pgfplots
. All the examples I have seen thus far call gnuplot
.
Best Answer
Actually, it is possible to draw implicit functions with LaTeX, if not with PGFPlots… but also in that case you need to cheat a little. Dan Luecking has implemented in its
mfpic
package, which is a (La)TeX interface to MetaPost (or METAFONT), a macro called\levelcurve[spec]{seed,step} {inequality}
,which works quite well beyond certain conditions, as said in the documentation, p. 44-45:
I've already used this macro to answer a similar question, and it worked very well in that case. I've just applied it on your simple example:
Typeset with LaTeX, then with MetaPost, and then with LaTeX again. The result is:
(As indicated in the documentation, the borders of the graph have been used to close the line which was the expected result.)
Still, as Paul Gessler noticed, an external program has worked behind the scene, namely MetaPost (be it as close to LaTeX as an external program can be).