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
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')
Based on Andrew’ answer, if you use pyplot instead of pylab, then:
fig = pyplot.gcf()
fig.canvas.set_window_title('My title')
You can also set the window title when you create the figure:
fig = plt.figure("YourWindowName")
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')
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.
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
.
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()
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
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')
Based on Andrew’ answer, if you use pyplot instead of pylab, then:
fig = pyplot.gcf()
fig.canvas.set_window_title('My title')
You can also set the window title when you create the figure:
fig = plt.figure("YourWindowName")
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')
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.
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
.
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()