Changing matplotlib window title is throwing strange error

Question:

I’m using python 3.6 in Jupyter lab on a linux mint machine to run this snippet of code

import matplotlib.pyplot as plt

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

..it returns the following error message:

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

I have checked the GUI backends. All are available and all of them return this error even if I force the backend using …

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

…before importing pyplot. The code has been working OK in Spyder but I’ve had to move to Jupyter. The matplotlib docs say that FigureManagerBase attributes include ‘window’. I’m stumped

Asked By: d8sconz

||

Answers:

To change the window title, use the code below:

import matplotlib.pyplot as plt

fig = plt.figure()
man = plt.get_current_fig_manager()
man.canvas.set_window_title("New Title")
Answered By: Ernest Li

Using python 3.8, matplotlib 3.5.3 the following works for me:

import matplotlib.pyplot as plt

fig = plt.figure()

man = plt.get_current_fig_manager()

man.set_window_title("New Title")
Answered By: Rich Tea
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.