热!!理工男表白函数Python实现

LOVE && 心形函数

代码块

import numpy as np
import matplotlib.pyplot as plt
import math
def character():
    plt.figure('Love')
    ax1 = plt.subplot(141)
    ax1.spines['right'].set_color('none')
    ax1.spines['top'].set_color('none')
    ax1.spines['left'].set_color('none')
    ax1.spines['bottom'].set_color('none')
    ax2 = plt.subplot(1,4,2)
    ax2.spines['right'].set_color('none')
    ax2.spines['top'].set_color('none')
    ax2.spines['left'].set_color('none')
    ax2.spines['bottom'].set_color('none')
    ax3 = plt.subplot(1,4,3)
    ax3.spines['right'].set_color('none')
    ax3.spines['top'].set_color('none')
    ax3.spines['left'].set_color('none')
    ax3.spines['bottom'].set_color('none')
    ax4 = plt.subplot(1,4,4)
    ax4.spines['right'].set_color('none')
    ax4.spines['top'].set_color('none')
    ax4.spines['left'].set_color('none')
    ax4.spines['bottom'].set_color('none')
    x=np.linspace(0.1,3,290)
    plt.sca(ax1)
    plt.plot(x,1/x,color='red')
    plt.xticks([])
    plt.yticks([])
    x=np.linspace(-3,3,100)
    for i in [1,-1]:
        plt.sca(ax2)
        plt.plot(x,i*np.sqrt(9-x*x),color='red')
        plt.xticks([])
        plt.yticks([])
    plt.sca(ax3)
    plt.plot(x,2*np.abs(x),color='red')
    plt.xticks([])
    plt.yticks([])
    plt.sca(ax4)
    plt.plot((-3)*np.abs(np.sin(x)),x,color='red')
    plt.xticks([])
    plt.yticks([])
    plt.show()

def heart():
    plt.figure('heart')
    ax1=plt.subplot(121)
    ax2=plt.subplot(122)
    t = np.linspace(-(2 * math.pi), 2 * math.pi, 100)
    i=1
    plt.sca(ax1)
    plt.plot(np.cos(i*t/2),np.sin(i*t/2)+np.abs((np.cos(i*t/2)))**(2/3),color='red')
    plt.title('i=1')
    i=50
    plt.sca(ax2)
    plt.plot(np.cos(i * t / 2), np.sin(i * t / 2) + np.abs((np.cos(i * t / 2))) ** (2 / 3), color='red')
    plt.title('i=50')
    plt.show()
if __name__=='__main__':
    character()
    heart()
  • love函数图像:

热!!理工男表白函数Python实现_第1张图片

  • 爱心函数图像:

热!!理工男表白函数Python实现_第2张图片

  • 参考数学公式:

  1. y=1/x

L字母

  1. 2.x ^2 +y ^2=9

O字母

  1. y=-2|x|

V字母

  1. x=-3|sin(y)|

E字母

  1. x ^2+(y-x ^(2/3)) ^2=1

心形


你可能感兴趣的:(跟随时代,python)