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

How to draw a heart shape in python

PHPz
Release: 2022-01-12 15:41:43
Original
41570 people have browsed it

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()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template