Change figure window title in pylab

PythonMatplotlib

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

fig = plt.figure("YourWindowName")

Solution 3 - Python

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

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

Solution 4 - Python

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

Solution 5 - Python

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

Solution 6 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOmarView Question on Stackoverflow
Solution 1 - PythonAndrew WalkerView Answer on Stackoverflow
Solution 2 - PythonAIpeterView Answer on Stackoverflow
Solution 3 - PythongoetzcView Answer on Stackoverflow
Solution 4 - PythonkhazView Answer on Stackoverflow
Solution 5 - PythonBenjoView Answer on Stackoverflow
Solution 6 - PythonGreenonlineView Answer on Stackoverflow