使用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()
相关推荐
o0o_-_3 分钟前
【go/gopls/mcp】官方gopls内置mcp server使用
开发语言·后端·golang
Dxy123931021618 分钟前
python把文件从一个文件复制到另一个文件夹
开发语言·python
sonrisa_1 小时前
collections模块
python
酷飞飞1 小时前
Qt Designer与事件处理
开发语言·qt·命令模式
折翼的恶魔1 小时前
数据分析:排序
python·数据分析·pandas
天雪浪子1 小时前
Python入门教程之赋值运算符
开发语言·python
Wadli1 小时前
C++语法 | static静态|单例模式
开发语言·c++·单例模式
他们都不看好你,偏偏你最不争气2 小时前
【iOS】AFNetworking
开发语言·macos·ios·objective-c
站大爷IP2 小时前
5个技巧写出专业Python代码:从新手到进阶的实用指南
python
Bigemap2 小时前
BigemapPro快速添加历史影像(Arcgis卫星地图历史地图)
java·开发语言