使用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()
相关推荐
查理零世13 分钟前
【蓝桥杯集训·每日一题2025】 AcWing 6134. 哞叫时间II python
python·算法·蓝桥杯
紫雾凌寒23 分钟前
解锁机器学习核心算法|神经网络:AI 领域的 “超级引擎”
人工智能·python·神经网络·算法·机器学习·卷积神经网络
sun lover35 分钟前
conda简单命令
python·conda
服务端相声演员44 分钟前
Oracle JDK、Open JDK zulu下载地址
java·开发语言
Mike_188702783511 小时前
1688代采下单API接口使用指南:实现商品采集与自动化下单
前端·python·自动化
19岁开始学习1 小时前
Go学习-入门
开发语言·学习·golang
青铜念诗1 小时前
python脚本文件设置进程优先级(在.py文件中实现)
开发语言·python
一念春风2 小时前
C# 背景 透明 抗锯齿 (效果完美)
开发语言·c#
Igallta_8136222 小时前
【小游戏】C++控制台版本俄罗斯轮盘赌
c语言·开发语言·c++·windows·游戏·游戏程序
Dyan_csdn2 小时前
【Python项目】文本相似度计算系统
开发语言·python