Oma*_*mar 76 python matplotlib
如何在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
Run Code Online (Sandbox Code Playgroud)
And*_*ker 110
如果您想要实际更改窗口,您可以执行以下操作:
fig = pylab.gcf()
fig.canvas.set_window_title('Test')
Run Code Online (Sandbox Code Playgroud)
goe*_*tzc 21
基于Andrew的回答,如果你使用pyplot而不是pylab,那么:
fig = pyplot.gcf()
fig.canvas.set_window_title('My title')
Run Code Online (Sandbox Code Playgroud)
AIp*_*ter 18
您还可以在创建图形时设置窗口标题:
fig = plt.figure("YourWindowName")
Run Code Online (Sandbox Code Playgroud)
小智 12
我用fig.canvas.set_window_title('The title')用fig用得到pyplot.figure(),它的工作很顺利:
import matplotlib.pyplot as plt
...
fig = plt.figure(0)
fig.canvas.set_window_title('Window 3D')
Run Code Online (Sandbox Code Playgroud)
(似乎.gcf()并.figure()在这里做类似的工作.)
小智 7
我发现这就是 pyplot 所需要的:
import matplotlib.pyplot as plt
....
plt.get_current_fig_manager().canvas.set_window_title('My Figure Name')
Run Code Online (Sandbox Code Playgroud)
我发现使用该canvas对象,如这两个示例所示:
fig.canvas.set_window_title('My title')
Run Code Online (Sandbox Code Playgroud)
plt.get_current_fig_manager().canvas.set_window_title('My Figure Name')
Run Code Online (Sandbox Code Playgroud)
从Benjo 的回答来看,两者都给出了这个警告:
fig.canvas.set_window_title('My title')
Run Code Online (Sandbox Code Playgroud)
解决方案似乎是调整Benjo 的答案并使用:
plt.get_current_fig_manager().set_window_title('My Figure Name')
Run Code Online (Sandbox Code Playgroud)
也就是说放弃使用canvas. 这样就消除了警告。