Is it possible to change the icon of a Matplotlibe figure window? My application has a button that opens a Figure window with a graph (created with Matplotlib). I managed to modify the application icon, but the figure window still has the 'Tk' icon, typical of Tkinter.
-
Not exactly what you asked for, but here is an example of embedding matplot figure in Tkinter : http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html (maybe overkill just to change the icon) – FabienAndre Apr 17 '12 at 14:52
-
@FabienAndre: Thanks, but I can't do what I want with that – maupertius Apr 17 '12 at 15:07
-
2Since you managed to change the icon of a regular tkinter window, displaying the matplotlib figure in a tkinter widget let you show it in its own Tkinter window (Toplevel is the widget that let you open window) of which you can change icon. Moreover, you are not forced to use another window which may provide interesting design alternatives. – FabienAndre Apr 17 '12 at 15:16
-
Mmm I don't quite understand. I create my figure using `imshow()` from the Tkinter app (which has the icon I want). Apparently, with the `imshow()` command the window that pops up still has the TKinter logo, and not my app one. – maupertius Apr 17 '12 at 15:21
-
it sounds like you're trying to do this: http://stackoverflow.com/questions/4073660/python-tkinter-embed-matplotlib-in-gui#4077424 that is the `imshow()` should be invoked from an axis in a figure-object and not from the pyplot-module directly. – deinonychusaur Apr 17 '12 at 20:22
5 Answers
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.

- 1,518
- 4
- 17
- 30
-
1Thanks for this answer..If you are using the wxAgg backend , the equivalent code is thismanager.window.SetIcon(wx.Icon("mylogo.ico",wx.BITMAP_TYPE_ICO)) – harijay May 06 '12 at 18:39
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)

- 31
- 3
Just adding this here, now that the Qt5Agg backend has made it's way into the mainstream. It's similar (pretty much the same) to the Qt4Agg backend as outlined by Sijie Chen's answer.
import os
import matplotlib.pyplot as plt
from PyQt5 import QtGui
# Whatever string that leads to the directory of the icon including its name
PATH_TO_ICON = os.path.dirname(__file__) + '/static/icons/icon.ico'
plt.get_current_fig_manager().window.setWindowIcon(QtGui.QIcon(PATH_TO_ICON))

- 51
- 6
If you are using Qt4Agg backend, the following code may help you:
thismanager = plt.get_current_fig_manager()
from PyQt4 import QtGui
thismanager.window.setWindowIcon(QtGui.QIcon((os.path.join('res','shepherd.png'))))

- 11
- 2
I found that under OS X with PyQT5, doing plt.get_current_fig_manager().window.setWindowIcon()
has no effect. To get the dock icon to change you have to call setWindowIcon()
on the QApplication
instance, not on the window.
What worked for me is:
QApplication.instance().setWindowIcon(QtGui.QIcon(icon_path))
Do mind that QApplication.instance()
will be None
until you have actually created a figure, so do that first.

- 1,298
- 2
- 9
- 16