Change icon in a Matplotlib figure window

I solved it in this way: BEFORE I press the button that creates the figure with imshow() and show(), I initialize the figure in this way:

plt.Figure()
thismanager = get_current_fig_manager()
thismanager.window.wm_iconbitmap("icon.ico")

so when I press show() the window has the icon I want.


For me the previous answer did not work, rather the following was required:

from Tkinter import PhotoImage
import matplotlib

thismanager = matplotlib.pyplot.get_current_fig_manager()
img = PhotoImage(file='filename.ppm')
thismanager.window.tk.call('wm', 'iconphoto', thismanager.window._w, img)