Python:画出笛卡尔心形曲线

极坐标方程:ρ=a(1sinθ)\rho = a (1-\sin\theta)

极坐标画图:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0.0, 2 * np.pi, 1000)
a = 5
rho = a * (1 - np.sin(theta))
plt.subplot(polar=True)
plt.plot(theta, rho, c = 'r')
plt.show()

在这里插入图片描述

直角坐标画图:
python程序:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0.5*np.pi, 1.5*np.pi, 1000)
sintheta = np.sin(theta)
a = 1
y = a * sintheta * (1 - sintheta)
x = np.sqrt((1 - sintheta) ** 2 - y ** 2)
x1 = np.hstack((x,-x[::-1]))  #x[::-1]意思是反转x
y1 = np.hstack((y,y[::-1]))
plt.plot(x1, y1, c = 'r')
plt.show()

在这里插入图片描述

posted @ 2018-12-26 09:27  xuejianbest  阅读(2921)  评论(0编辑  收藏  举报