python 畫心形


python 利用 matplotlib 和 numpy 畫心形。

 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3 
 4 #初始化數據
 5 init = np.arange(-np.pi, np.pi, 0.001)
 6 y = np.subtract(np.multiply(2, np.cos(init)), np.cos(np.multiply(2, init)))
 7 x = np.subtract(np.multiply(2, np.sin(init)), np.sin(np.multiply(2, init)))
 8 
 9 #畫圖
10 plt.plot(x, y)
11 plt.fill_between(x, y, facecolor='red')
12 plt.show()

結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM