Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting system of (implicit) equations in matplotlib [duplicate]

First off, I'm new to python and matplotlib. I need to plot several systems of implicit equations in one figure.

The equations are in form of:

3x+2y=1

Is there an easy way to plot these, other than first making the equations explicit (i.e. y=...)?

like image 959
Milo Wielondek Avatar asked Jan 14 '11 11:01

Milo Wielondek


2 Answers

import numpy as np
import matplotlib.pyplot as plt
# Note the order of y,x.
y,x=np.ogrid[-5:5:100j,-5:5:100j]
plt.contour(x.ravel(),y.ravel(),3*x+2*y,[1])
plt.show()

alt text

like image 166
unutbu Avatar answered Oct 08 '22 17:10

unutbu


You can use contour() to do implicit plots in two space dimensions:

x = numpy.linspace(-2., 2.)
y = numpy.linspace(-2., 2.)[:, None]
contour(x, y.ravel(), 3*x + 2*y, [1])

In 3 dimensions, I suggest using Mayavi instead of matplotlib.

like image 33
Sven Marnach Avatar answered Oct 08 '22 16:10

Sven Marnach