To plot a function defined with def in Python, you can −
Set the character size and adjust the padding between and around the subplots.
Create a user-defined function using def. H. f(x).
Create x data points in NumPy.
Plot x and f(x) using the plot() method. To display the image, use the show() method.