开发者

Change figure window title in pylab

开发者 https://www.devze.com 2023-03-01 00:29 出处:网络
How can I set a figure window\'s 开发者_开发百科title in pylab/python? fig = figure(9) # 9 is now the title of the window

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


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

fig = plt.figure("YourWindowName")


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

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


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

Change figure window title in pylab

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


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.

See: matplotlib.pyplot.suptitle

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号