Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to plot implicit equations using Matplotlib?

I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?

like image 551
Geddes Avatar asked Mar 20 '10 20:03

Geddes


2 Answers

I don't believe there's very good support for this, but you could try something like

import matplotlib.pyplot from numpy import arange from numpy import meshgrid  delta = 0.025 xrange = arange(-5.0, 20.0, delta) yrange = arange(-5.0, 20.0, delta) X, Y = meshgrid(xrange,yrange)  # F is one side of the equation, G is the other F = Y**X G = X**Y  matplotlib.pyplot.contour(X, Y, (F - G), [0]) matplotlib.pyplot.show() 

See the API docs for contour: if the fourth argument is a sequence then it specifies which contour lines to plot. But the plot will only be as good as the resolution of your ranges, and there are certain features it may never get right, often at self-intersection points.

like image 128
Steve Avatar answered Sep 23 '22 20:09

Steve


Since you've tagged this question with sympy, I will give such an example.

From the documentation: http://docs.sympy.org/latest/modules/plotting.html.

from sympy import var, plot_implicit var('x y') plot_implicit(x*y**3 - y*x**3) 
like image 24
Gary Kerr Avatar answered Sep 22 '22 20:09

Gary Kerr