如何在Python上通过等式绘制椭圆? [英] How to plot an ellipse by its equation on Python?

查看:462
本文介绍了如何在Python上通过等式绘制椭圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个等式:

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

我如何不能使用Matplotlib.pyplot和Numpy软件包对其进行绘制?

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

推荐答案

我的解决方案是:为给定的x和z网格计算方程的每一边.然后,我轮廓满足方程式的点.一侧减去另一侧等于零.

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])

这篇关于如何在Python上通过等式绘制椭圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆