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

news/2024/9/23 17:42:27/

使用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)**3y = 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()

http://www.ppmy.cn/news/1464227.html

相关文章

小红书引流获客软件,轻松成为爆款达人

在这个信息爆炸的时代,小红书凭借其独特的内容分享社区模式,迅速成为了品牌和个体创业者不可忽视的营销宝地。作为一个集生活方式分享、购物心得、美妆教程、旅行攻略等于一身的平台,小红书聚集了大量追求品质生活的年轻用户群体。对于想要在…

LeetCode 63.不同路径Ⅱ

思路&#xff1a; 在有障碍物的地方增加一个判断即可 class Solution { public:int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {int dp[105][105];int mobstacleGrid.size();int nobstacleGrid[0].size();for(int i0;i<m;i){for(int j0…

Linux安装zsh并配置oh-my-zsh

配置oh-my-zsh 查看当前shell安装zsh切换到zsh配置ohmysh 查看当前shell cat /etc/shells# /etc/shells: valid login shells /bin/sh /bin/bash /usr/bin/bash /bin/rbash /usr/bin/rbash /bin/dash /usr/bin/dash安装zsh sudo apt install zsh# /etc/shells: valid login s…

AWS迁移与传输之Migration Hub

AWS Migration Hub是一种集中化的迁移管理服务&#xff0c;可帮助企业规划、跟踪和管理在亚马逊云中进行的各种迁移活动。包括应用程序迁移、数据库迁移、服务器迁移等。 AWS Migration Hub (Migration Hub) 提供一个位置来跟踪使用多个 AWS 工具和合作伙伴解决方案的迁移任务…

前端---闭包【防抖以及节流】----面试高频!

1.什么闭包 释放闭包 从以上看出&#xff1a;一般函数调用一次会把内部的数据进行清除--但是这种操作却可以一起保留局部作用域的数据 // 优点:1、可以读取函数内部的变量 2、让这些变量始中存在局部作用域当中 2.闭包产生的两种业务场景&#xff1a;防抖、节流 2.1防抖 举…

浅谈MySQL事务

目录 一&#xff0c;事务的引入 上述的特性叫做“原子性”&#xff08;事务最核心操作&#xff0c;事务还具备别的性质在下文&#xff09;&#xff1b; 二&#xff0c;日志体系 三&#xff0c;事务的使用 四&#xff0c;事务的基本特性 1.脏读&#xff1a; 2.不可重复读 …

Android 11 AudioPolicyService 启动流程

AudioPolicyService在init进程中启动&#xff0c;源码路径&#xff1a;frameworks/av/media/audioserver/audioserver.rc service audioserver /system/bin/audioserverclass coreuser audioserver# media gid needed for /dev/fm (radio) and for /data/misc/media (tee)grou…

修复CentOS 6.6服务器YUM和RPM功能异常的技术实践20240523

修复CentOS 6.6服务器YUM和RPM功能异常的技术实践 引言 在复杂的生产环境中&#xff0c;服务器的稳定性至关重要。近期&#xff0c;我们遇到了一台CentOS 6.6服务器在执行yum update -y时被中断&#xff0c;导致YUM和RPM功能异常的问题。本文将详细介绍问题的诊断、解决过程以及…