Omar
Omar

Reputation: 40202

Change figure window title in pylab

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

Upvotes: 133

Views: 156703

Answers (8)

Greenonline
Greenonline

Reputation: 1377

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.

Upvotes: 6

Mautoz
Mautoz

Reputation: 79

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

Upvotes: 6

Konstantin Andreev
Konstantin Andreev

Reputation: 9

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

Upvotes: 0

Andrew Walker
Andrew Walker

Reputation: 42500

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

Upvotes: 185

Benjo
Benjo

Reputation: 147

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

Upvotes: 7

AIpeter
AIpeter

Reputation: 948

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

fig = plt.figure("YourWindowName")

Upvotes: 69

khaz
khaz

Reputation: 211

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

Upvotes: 21

goetz
goetz

Reputation: 2263

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

fig = pyplot.gcf()
fig.canvas.set_window_title('My title')

Upvotes: 39

Related Questions