d8sconz
d8sconz

Reputation: 279

Changing matplotlib window title is throwing strange error

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

Upvotes: 1

Views: 2825

Answers (2)

Rich Tea
Rich Tea

Reputation: 31

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

Upvotes: 3

Ernest Li
Ernest Li

Reputation: 128

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

Upvotes: 5

Related Questions