You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: canvas.manager.set_window_title does not work to figure with WebAgg backend #29256
For other backends such as qtagg the use of set_window_title does indeed set the title in the title bar of the window displaying the figure, and figure.set_label() (inherited from the Artist class) is used to uniquely identify the figure and is the default filename used when saving the figure, it is not used as a visual title anywhere.
I expect there has been some historical confusion here as webagg is different from most backends in that a figure is displayed in a browser tab and there are two possible titles here, one in the title bar of the tab and the other rendered at the top of the canvas in the page displaying the figure.
For consistency with other backends like qtagg I think the correct behaviour is to keep the set_window_title implementation as it is and change the handle_refresh to read self._window_title rather than self.figure.get_label(). But this will change the behaviour for anyone currently using figure.set_label to change the title.
An alternative fix is to keep the text above the figure in the web page as the figure label, and use set_window_title to set the text in the browser tab. This won't break anyone's current use of figure.set_label. AFAICT from an implementation point of view this would need another message type to be handled by lib/matplotlib/backends/web_backend/js/mpl.js which would set the document.title.
An alternative fix is to keep the text above the figure in the web page as the figure label, and use set_window_title to set the text in the browser tab. This won't break anyone's current use of figure.set_label. AFAICT from an implementation point of view this would need another message type to be handled by lib/matplotlib/backends/web_backend/js/mpl.js which would set the document.title.
WebAgg supports multiple figures in a single webpage; we can't map a single figure's title to the entire document.
For consistency with other backends like qtagg I think the correct behaviour is to keep the set_window_title implementation as it is and change the handle_refresh to read self._window_title rather than self.figure.get_label(). But this will change the behaviour for anyone currently using figure.set_label to change the title.
I agree, this is the way to go.
AFAICS, the meaning of Figure.set_label is not documented anywhere. Technically it's inherited from Artist.set_label, which refers to legend labels. We have some internal code that repurposes it for figure, but that's not documented. More generally, label is a heavily overloaded term and we should try to use it less. Semi-related: #28584, where we disallowed Axis.set_label as that was also causing confusion.
Activity
ianthomas23 commentedon Dec 8, 2024
Thanks for the report, it is an interesting bug!
When using the
webaggbackend theset_window_titleinitially does what you want which is to update thefigure_labelin the browser:matplotlib/lib/matplotlib/backends/backend_webagg_core.py
Lines 454 to 456 in 9af426b
However on the next render, which is essentially immediate, the
figure_labelis reset to the contents offigure.get_label():matplotlib/lib/matplotlib/backends/backend_webagg_core.py
Lines 330 to 334 in 9af426b
For other backends such as
qtaggthe use ofset_window_titledoes indeed set the title in the title bar of the window displaying the figure, andfigure.set_label()(inherited from theArtistclass) is used to uniquely identify the figure and is the default filename used when saving the figure, it is not used as a visual title anywhere.I expect there has been some historical confusion here as
webaggis different from most backends in that a figure is displayed in a browser tab and there are two possible titles here, one in the title bar of the tab and the other rendered at the top of the canvas in the page displaying the figure.For consistency with other backends like
qtaggI think the correct behaviour is to keep theset_window_titleimplementation as it is and change thehandle_refreshto readself._window_titlerather thanself.figure.get_label(). But this will change the behaviour for anyone currently usingfigure.set_labelto change the title.An alternative fix is to keep the text above the figure in the web page as the figure label, and use
set_window_titleto set the text in the browser tab. This won't break anyone's current use offigure.set_label. AFAICT from an implementation point of view this would need another message type to be handled bylib/matplotlib/backends/web_backend/js/mpl.jswhich would set thedocument.title.QuLogic commentedon Dec 10, 2024
WebAgg supports multiple figures in a single webpage; we can't map a single figure's title to the entire document.
timhoffm commentedon Dec 11, 2024
I agree, this is the way to go.
AFAICS, the meaning of
Figure.set_labelis not documented anywhere. Technically it's inherited fromArtist.set_label, which refers to legend labels. We have some internal code that repurposes it for figure, but that's not documented. More generally,labelis a heavily overloaded term and we should try to use it less. Semi-related: #28584, where we disallowedAxis.set_labelas that was also causing confusion.ianthomas23 commentedon Dec 11, 2024
Thanks @QuLogic and @timhoffm for the clarification. I should be able to come up a PR for this soon.