Matplotlib uses a backend to control how plots are drawn and displayed. You can set the backend explicitly using matplotlib.use('backend_name') before importing pyplot. If you don't set it, matplotlib chooses a default backend based on your system. The backend can be interactive (showing windows) or non-interactive (saving files). Setting the backend after importing pyplot does not change the active backend. In the example, we set the backend to 'Agg', which is non-interactive, then create a plot and save it to a file. This process ensures the plot is saved without opening any window.