import matplotlib.pyplot as plt
import numpy as np
# Define the parametric equations for the heart shape
t = np.linspace(0, 2 * np.pi, 1000)
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)
# Plot the heart shape
plt.figure(figsize=(6,6))
plt.plot(x, y, 'r')
plt.title('Heart Shape')
plt.axis('off') # Turn off the axis
plt.axis('equal') # Ensure the shape is not distorted
plt.fill_between(x, y, color='red') # Fill the heart shape with red color
plt.show()
输出结果:
Matplotlib is building the font cache; this may take a moment.