Change figure window title in pylab

Question:

How can I set a figure window’s title in pylab/python?

fig = figure(9) # 9 is now the title of the window
fig.set_title("Test") #doesn't work
fig.title = "Test" #doesn't work
Asked By: Omar

||

Answers:

If you want to actually change the window you can do:

fig = pylab.gcf()
fig.canvas.set_window_title('Test')

Update 2021-05-15:

The solution above is deprecated (see here). instead use

fig = pylab.gcf()
fig.canvas.manager.set_window_title('Test')
Answered By: Andrew Walker

Based on Andrew’ answer, if you use pyplot instead of pylab, then:

fig = pyplot.gcf()
fig.canvas.set_window_title('My title')
Answered By: goetz

I used fig.canvas.set_window_title('The title') with fig obtained with pyplot.figure() and it worked well too:

import matplotlib.pyplot as plt
...
fig = plt.figure(0)
fig.canvas.set_window_title('Window 3D')

enter image description here

(Seems .gcf() and .figure() does similar job here.)

Answered By: khaz

You can also set the window title when you create the figure:

fig = plt.figure("YourWindowName")
Answered By: AIpeter

I found this was what I needed for pyplot:

import matplotlib.pyplot as plt
....
plt.get_current_fig_manager().canvas.set_window_title('My Figure Name')
Answered By: Benjo

I have found that using the canvas object, as in these two examples:

fig.canvas.set_window_title('My title')

as suggested by some other answers (1, 2), and

plt.get_current_fig_manager().canvas.set_window_title('My Figure Name')

from benjo’s answer, both give this warning:

The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead.

The solution seems to be to adapt Benjo’s answer and use:

plt.get_current_fig_manager().set_window_title('My Figure Name')

That is to say drop the use of canvas. This gets rid of the warning.

Answered By: Greenonline

From Matplotlib 3.4 and later the function set_window_title was deprecated.

You can use matplotlib.pyplot.suptitle() which behaves like set_window_title.

See: matplotlib.pyplot.suptitle

Answered By: Konstantin Andreev

Code that works now (09.04.23, matplotlib 3.7.1):

import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [2,4,6,8,10]
plt.plot(x,y)
plt.get_current_fig_manager().set_window_title('My Figure Name')
plt.show()
Answered By: Mautoz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.