Where are you running the code — Jupyter Notebook or the command line?
In Jupyter Notebook, we need to restart the kernel before setting a new backend via matplotlib.use(), otherwise it will trigger the warning
This call to matplotlib.use() has no effect because the backend has already been chosen. Additionally, to avoid the warning
matplotlib.use() must be called *before* pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time, we must call matplotlib.use() before importing matplotlib.pyplot.
I’ve updated my article to include my complete code. Hope it helps!