Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot an ellipse by its equation on Python?

So I have this equation:

x^2 + 4*(z+10)^2 = e^(-0.05*z)

How cant I plot it using, for example, Matplotlib.pyplot and Numpy packages?

like image 780
iury simoes-sousa Avatar asked Apr 11 '15 19:04

iury simoes-sousa


People also ask

How do you graph an ellipse in Python?

Wand ellipse() function in Python Just similar to drawing circle the ellipse() function requires two pairs of point that is, origin and a pair of (x, y) radius of the ellipse. To draw a partial ellipse, provide a pair of starting & ending degrees as the third parameter. pair which represents origin x and y of ellipse.

How do you plot an ellipse?

To graph an ellipse, mark points a units left and right from the center and points b units up and down from the center. Draw an ellipse through these points. The orientation of an ellipse is determined by a and b. If a>b then the ellipse is wider than it is tall and is considered to be a horizontal ellipse.


2 Answers

My solution is: Calculate each side of equation for a given x and z gridded. Then I contour points that satisfy the equation. One side minus other equals to zero.

import numpy as np
import matplotlib.pyplot as plt

z = -np.linspace(9,15,100)
x = np.linspace(-26,26,1000)

x,z = np.meshgrid(x,z)

Z = -np.exp(-0.05*z) +4*(z+10)**2 
X = x**2


plt.contour(x,z,(X+Z),[0])
plt.xlim([-1.5,1.5])
plt.ylim([-11.5,-8.5])

Out

like image 165
iury simoes-sousa Avatar answered Oct 17 '22 08:10

iury simoes-sousa


Use the plot_implicit function of sympy http://docs.sympy.org/latest/modules/plotting.html or use Sage http://www.sagemath.org/.

like image 1
Edward Doolittle Avatar answered Oct 17 '22 10:10

Edward Doolittle