How can I save figure in matplotlib to an image file instead of opening it in a GUI?

In one of my data pipelines, I didn’t want any GUI pop-ups. So I skipped plt.show() entirely and just used plt.savefig('output_chart.png').

That’s the cleanest way to matplotlib save figure silently, especially when running on servers or CI where no display is available.