Use set_window_title rather than set_label to set title of webagg figure#29338
Conversation
|
What's the behavior with respect to the label? I assume the label is used as a fallback if the window title is not set? If that's correct, the behavoir should be documented, with the comment that it results in backward compatibility for previous users of |
Unfortunately it is not that simple. If the window matplotlib/lib/matplotlib/backend_bases.py Line 2612 in f2717a5 regardless of the backend used. This can be overridden by passing a To demonstrate this use import matplotlib as mpl
mpl.use("qtagg")
#mpl.use('webagg')
import matplotlib.pyplot as plt
# 1. Set title using set_window_title
fig1, ax1 = plt.subplots(figsize=(3, 2))
fig1.canvas.manager.set_window_title('Using set_window_title')
# 2. Set title using label passed to Figure constructor
fig2, ax2 = plt.subplots(figsize=(3, 2), label="Label in constructor")
# 3. Using Figure.set_label has no effect on the window title
fig3, ax3 = plt.subplots(figsize=(3, 2))
fig3.set_label("This is not used in the title")
plt.show()and the title outputs are the same for So this PR brings |


Closes #29256.
Previously when using the
webaggbackend if you wanted to change the title above a figure you would usefigure.set_label('whatever')and if you usedfigure.canvas.manager.set_window_title('whatever')it would be ignored. This was inconsistent with other backends which use the latter.This PR changes the behaviour so that
figure.canvas.manager.set_window_title('whatever')is used now forwebagg, the same as the other backends.There is no test as there isn't currently any visual testing of the
webaggbackend. There is some draft work underway in #23540 for this. So here is a demonstration instead, using this code:the
webaggoutput is:which is consistent with the output produced by e.g. the
qtaggbackend:PR checklist
WebAggbackend #29256" is in the body of the PR description to link the related issue