更改matplotlib窗口标题会引发奇怪的错误

时间:2018-10-12 03:42:52

标签: python matplotlib

我正在Linux薄荷机上的Jupyter实验室中使用python 3.6来运行此代码段

import matplotlib.pyplot as plt

fig = plt.figure()
man = plt.get_current_fig_manager()
man.window.setWindowTitle("New Title")

.. it返回以下错误消息:

AttributeError: 'FigureManagerBase' object has no attribute 'window'

我已经检查了GUI后端。所有人都可用,即使我强制使用...

import matplotlib
matplotlib.use(<gui>,warn=False, force=True)

...导入pyplot之前。该代码在Spyder中运行正常,但我不得不移至Jupyter。 matplotlib文档说FigureManagerBase属性包括'window'。我很困惑

1 个答案:

答案 0 :(得分:1)

要更改窗口标题,请使用以下代码:

import matplotlib.pyplot as plt

fig = plt.figure()
man = plt.get_current_fig_manager()
man.canvas.set_window_title("New Title")
相关问题