Home  >  Article  >  Backend Development  >  How to draw a heart shape in python

How to draw a heart shape in python

PHPz
PHPzOriginal
2020-09-25 16:12:3041551browse

How to draw a heart shape in python: use matplotlib and numpy to draw a heart shape, the code is [init = np.arange(-np.pi, np.pi, 0.001);plt.fill_between(x, y, facecolor='red')].

How to draw a heart shape in python

Related learning recommendations: python tutorial

How to draw a heart shape in python:

python uses matplotlib and numpy to draw a heart shape.

import matplotlib.pyplot as plt
import numpy as np
#初始化数据
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()

Result:

How to draw a heart shape in python

The above is the detailed content of How to draw a heart shape in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn