使用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()
相关推荐
黎雁·泠崖12 分钟前
【魔法森林冒险】2/14 抽象层设计:Figure/Person类(所有角色的基石)
java·开发语言
aiguangyuan38 分钟前
使用LSTM进行情感分类:原理与实现剖析
人工智能·python·nlp
季明洵39 分钟前
C语言实现单链表
c语言·开发语言·数据结构·算法·链表
小小张说故事1 小时前
BeautifulSoup:Python网页解析的优雅利器
后端·爬虫·python
墨雪不会编程1 小时前
C++之【深入理解Vector】三部曲最终章
开发语言·c++
luoluoal1 小时前
基于python的医疗领域用户问答的意图识别算法研究(源码+文档)
python
Shi_haoliu1 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi
浅念-1 小时前
C语言编译与链接全流程:从源码到可执行程序的幕后之旅
c语言·开发语言·数据结构·经验分享·笔记·学习·算法
ZH15455891311 小时前
Flutter for OpenHarmony Python学习助手实战:API接口开发的实现
python·学习·flutter
小宋10211 小时前
Java 项目结构 vs Python 项目结构:如何快速搭一个可跑项目
java·开发语言·python