Problem with saving the plot using matplotlib
Using pyplot interface, you have to call plt.savefig() before plt.show(). If you change the order, the figure is destroyed once the window is closed and a new empty one is created by plt.savefig().
I use plt.savefig(pngpath, dpi=300), where the pngpath is the path where I want it to save. The png file as such is being created but is blank when I try and open it. Interestingly, the plt.show() right before this plt.savefig() works perfectly fine.
EDIT 1: As ONDRO pointed out, I used plt.show() after plt.savefig() and the plot saved perfectly as intended. Also, I will make sure to add minimal reproduceable code next time. Thank you ONDRO and everyone else for helping me out!