Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change icon in a Matplotlib figure window

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.

like image 605
maupertius Avatar asked Apr 17 '12 10:04

maupertius


People also ask

How do I change the title of a matplotlib window?

MatPlotLib with Python gcf(), we can create a fig variable and can set the fig. canvas. set_window_title('Setting up window title. ') window title.

How do I change the plot window in matplotlib?

Matplotlib change bar plot size Here we'll use the figsize() method to change the bar plot size. Import matplotlib. pyplot library. To change the figure size, use figsize argument and set the width and the height of the plot.

How do you change Figsize in Pyplot?

If you've already got the figure created, say it's 'figure 1' (that's the default one when you're using pyplot), you can use figure(num=1, figsize=(8, 6), ...) to change it's size etc.

How do I change the shape in matplotlib?

Marker Shape Just use the marker argument of the plot() function to custom the shape of the data points.


2 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.

like image 95
maupertius Avatar answered Sep 20 '22 23:09

maupertius


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)
like image 33
gavin Avatar answered Sep 20 '22 23:09

gavin