以下是Python代码,用Matplotlib库绘制六个曲线和一个填充爱心的图形:
import matplotlib.pyplot as plt
import numpy as np
# 生成正弦曲线的数据
x = np.arange(0, 6 * np.pi, 0.1)
y_sin = np.sin(x)
# 生成余弦曲线的数据
y_cos = np.cos(x)
# 生成正切曲线的数据
y_tan = np.tan(x)
# 生成余切曲线的数据
y_cot = 1 / np.tan(x)
# 生成蝴蝶曲线的数据
x_1 = np.sin(x - np.pi / 2) * np.exp(np.cos(x)) - 2 * np.sin(x) + np.power(np.sin(x / 12), 5)
y_1 = np.cos(x - np.pi / 2) * np.exp(np.cos(x)) - 2 * np.cos(x) - np.power(np.cos(x / 12), 5)
x_2 = -x_1
y_2 = y_1
# 生成红色填充爱心的数据
theta = np.linspace(0, 2 * np.pi, 200)
r = np.power(np.power(np.sin(theta), 2) * np.sqrt(np.abs(np.cos(theta))), -0.335) + 0.5 * np.power(np.power(np.cos(theta), 2) * np.sqrt(np.abs(np.sin(theta))), -0.335)
x_heart = r * np.sin(theta)
y_heart = r * np.cos(theta)
# 旋转蝴蝶曲线
x_1, y_1 = np.cos(np.pi/2) * x_1 + np.sin(np.pi/2) * y_1, -np.sin(np.pi/2) * x_1 + np.cos(np.pi/2) * y_1
x_2, y_2 = np.cos(np.pi/2) * x_2 + np.sin(np.pi/2) * y_2, -np.sin(np.pi/2) * x_2 + np.cos(np.pi/2) * y_2
# 绘制图形
fig, ax = plt.subplots()
ax.plot(x, y_sin)
ax.plot(x, y_cos)
ax.plot(x, y_tan)
ax.plot(x, y_cot)
ax.plot(x_1, y_1, color='purple')
ax.plot(x_2, y_2, color='purple')
ax.fill(x_heart, y_heart, color='red')
plt.show()
生成的图形如下所示:
其中,橙色曲线为正弦曲线,蓝色曲线为余弦曲线,绿色曲线为正切曲线,紫色曲线为余切曲线,紫色曲线为顺时针旋转270°的蝴蝶曲线,红色填充为爱心。