If you're using Jupyter notebook, just mention this line int he first cell. This syntax works on the Jupyter Notebook.
In : %matplotlib inline
This is a really good command and works best with Jupiter's IPython Notebook. Its basically used to show an image automatically within the browser without using show().
But in your python script, you can't use this syntax. You can eliminate the use of this function completely and replace it with the bellow code:
import matplotlib.pyplot as plt