python繪制心形的方法:利用matplotlib和numpy畫心形,代碼為【init = np.arange(-np.pi, np.pi, 0.001);plt.fill_between(x, y, facecolor='red')】。
相關(guān)學(xué)習(xí)推薦:python教程
python繪制心形的方法:
python 利用 matplotlib 和 numpy 畫心形。
import matplotlib.pyplot as plt import numpy as np #初始化數(shù)據(jù) init = np.arange(-np.pi, np.pi, 0.001) y = np.subtract(np.multiply(2, np.cos(init)), np.cos(np.multiply(2, init))) x = np.subtract(np.multiply(2, np.sin(init)), np.sin(np.multiply(2, init))) #畫圖 plt.plot(x, y) plt.fill_between(x, y, facecolor='red') plt.show()
結(jié)果: