由此我们得到的结论是,n为奇数时,花瓣为n;为偶数时,花瓣为n的2倍。所使用的源码:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,8))
plt.ylim([-2*np.pi, 2*np.pi])
plt.xlim([-2*np.pi, 2*np.pi])
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data', 0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data', 0))
a = np.arange(-np.pi, np.pi, np.pi / 1000)
n = 5
x = np.cos(n*a) * np.cos(a)
y = np.cos(n*a) * np.sin(a)
plt.plot(x,y)
plt.fill_between(x, y, color='y')
plt.show()