python画出心形图-python如何绘制心形

python绘制心形的方法:利用matplotlib和numpy画心形,代码为【init = np.arange(-np.pi, np.pi, 0.001);plt.fill_between(x, y, facecolor='red')】。

2020092114585313590.jpg相关学习推荐:python教程

python绘制心形的方法:

python 利用 matplotlib 和 numpy 画心形。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()

结果:

1600671494777145.png

以上就是python如何绘制心形的详细内容,更多请关注gxlcms其它相关文章!

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.php.cn/python-tutorials-460259.html