月亮代表我的❤python却说不~

考研党曾经受尽心形函数七十二变之苦
如今敢问在座各位对心形曲线方程还知多少呢?

下面一起来了解一下心形曲线的几种表达形式吧~
1.直角坐标方程

x 2 + y 2 + a x = a ∗ s q r t ( x 2 + y 2 ) x^2+y^2+ax=a*sqrt(x^2+y^2) x2+y2+ax=asqrt(x2+y2)

2.极坐标方程
水 平 方 向 : r = a ( 1 − c o s θ ) 水平方向:r=a(1-cosθ) r=a(1cosθ)

垂 直 方 向 : r = a ( 1 − s i n θ ) 垂直方向:r=a(1-sinθ) r=a(1sinθ)
3.参数方程
x = a ( 2 c o s ( t ) − c o s ( 2 t ) ) x=a(2cos(t)-cos(2t)) x=a(2cos(t)cos(2t))

y = a ( 2 s i n ( t ) − s i n ( 2 t ) ) y=a(2sin(t)-sin(2t)) y=a(2sin(t)sin(2t))

话不多说,码来到~

import numpy as np
import matplotlib.pyplot as plt

# 生成x坐标 -2到2范围 的 等差数列数组,数组元素一共1500个
x = np.linspace(-2, 2, 1500)

# 上半部分爱心函数线段
y1 = np.sqrt(1 - (np.abs(x) - 1) ** 2)

# 下半部分爱心函数线段
y2 = -3 * np.sqrt(1 - (np.abs(x) / 2) ** 0.5)

# fill_between是填充线段内部的颜色
plt.fill_between(x, y1, color='red')
plt.fill_between(x, y2, color='red')

# 控制x轴的范围
plt.xlim([-2.5, 2.5])

# 生成文本,指定文本位置 ,字体大小
plt.text(0, -0.4, 'I love you!', fontsize=30, fontweight='bold', color='yellow', horizontalalignment='center')

# 去除刻度
plt.axis('off')
plt.show()

在这里插入图片描述

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Albot-CV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值