Change icon in a Matplotlib figure window

前端 未结 5 1181
难免孤独
难免孤独 2020-12-11 05:18

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

5条回答
  •  长情又很酷
    2020-12-11 05:37

    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))
    

提交回复
热议问题