Skip to content

Instantly share code, notes, and snippets.

@araujo88
Created June 12, 2024 20:31
Show Gist options
  • Save araujo88/48385282da8fb05376b774a803b3c854 to your computer and use it in GitHub Desktop.
Save araujo88/48385282da8fb05376b774a803b3c854 to your computer and use it in GitHub Desktop.
Heart shape in Python (matplotlib)
import numpy as np
import matplotlib.pyplot as plt
# Define the implicit function for the heart shape
def heart_shape(x, y):
return (x**2 + y**2 - 1)**3 - x**2 * y**3
# Create a grid of x, y points
x = np.linspace(-1.5, 1.5, 400)
y = np.linspace(-1.5, 1.5, 400)
x, y = np.meshgrid(x, y)
# Compute the function values
z = heart_shape(x, y)
# Plotting
plt.figure(figsize=(6, 6))
plt.contour(x, y, z, levels=[0], colors='red')
plt.title('Heart Shape Plot')
plt.axis('equal')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment