How to plot an ellipse by its equation on Python?

前端 未结 2 509
[愿得一人]
[愿得一人] 2021-01-13 06:39

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?

相关标签:
2条回答
  • 2021-01-13 07:30

    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

    0 讨论(0)
  • 2021-01-13 07:34

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

    0 讨论(0)
提交回复
热议问题