使用python绘制一个五颜六色的爱心

使用python绘制一个五颜六色的爱心

  • 介绍
  • 效果
  • 代码

介绍

使用numpy与matplotlib绘制一个七彩爱心!

效果

代码

python 复制代码
import numpy as np
import matplotlib.pyplot as plt

# Heart shape function
def heart_shape(t):
    x = 16 * np.sin(t)**3
    y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
    return x, y

# Create a figure and axis
fig, ax = plt.subplots()

# Generate values for t
t = np.linspace(0, 2 * np.pi, 1000)

# Generate heart shape coordinates
x, y = heart_shape(t)

# Create a scatter plot with gradient colors
colors = plt.cm.rainbow(np.linspace(0, 1, len(t)))
for i in range(len(t) - 1):
    ax.plot(x[i:i+2], y[i:i+2], color=colors[i], linewidth=2)

# Remove the axes
ax.axis('off')

# Set the aspect of the plot to be equal
ax.set_aspect('equal')

# Show the plot
plt.show()
相关推荐
hongyucai8 小时前
详解rlinf强化学习四步曲
人工智能·python·算法·架构
c_lb72888 小时前
2026年下半年AI量化工具,阶段不同重点也不同
人工智能·python
北京阿法龙科技有限公司8 小时前
AR智能眼镜安防应用核心指标:识别距离筑牢防线
java·开发语言·ar
杜子不疼.8 小时前
【C++】继承—C++的秘密武器,get父类的智慧
开发语言·c++
Xpower 178 小时前
详细解释 Codex 最近一次功能更新,以及 GPT-5.6 Sol、Terra、Luna 的能力、价格、使用方式和适用场景。
人工智能·python·gpt·学习
阿pin8 小时前
Android随笔-View绘制流程
android·开发语言·view
许彰午8 小时前
87_Python Django模型与数据库
数据库·python·django
没钥匙的锁18 小时前
04-Java面向对象基础
java·开发语言·mongodb
程序员小远8 小时前
性能测试之性能调优
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·性能测试
敖行客 Allthinker9 小时前
IM 融合专题:后端架构师的核心修炼
java·开发语言·数据库