Created
June 12, 2024 20:31
-
-
Save leo-aa88/48385282da8fb05376b774a803b3c854 to your computer and use it in GitHub Desktop.
Heart shape in Python (matplotlib)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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