Hey guys in this blog we will see Python Code to make a heart. This is going to be a very short and interesting blog, So without any further due, let’s do it…

## Python Code to make a heart using Matplotlib

import matplotlib.pyplot as plt import numpy as np t = np.linspace(0, 2 * np.pi, 100) 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) plt.plot(x, y, 'r-', linewidth=2) plt.show()

- This program uses the

library to create a plot, and the**matplotlib.pyplot**`numpy`

library to create data points for the x and y coordinates of the heart shape. - The

function is used to create a range of values for the variable**np.linspace()**`t`

, and the

and**np.sin**

functions are used to calculate the x and y coordinates of the heart shape.**np.cos** - The

function is then used to plot the x and y coordinates, and the**plt.plot()**`r-`

argument specifies that the line should be red. - Finally, the

function is used to display the plot.**plt.show()**

You can run this code in a Python environment like IDLE, Jupyter notebook or any Python IDE to see the heart shape.

### Result

## Download Python Code to make a heart

So this was a very short Python Code to make a heart. If you have any doubt regarding this, you can contact me by mail.

Check out our other python programming examples…