Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use set_window_title rather than set_label to set title of webagg figure#29338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

ianthomas23
Copy link
Member

Closes#29256.

Previously when using thewebagg backend 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 thatfigure.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 thewebagg backend. There is some draft work underway in#23540 for this. So here is a demonstration instead, using this code:

importmatplotlibasmplmpl.use('webagg')importmatplotlib.pyplotaspltfig1,ax1=plt.subplots(figsize=(3,2))ax1.plot([1,3,2,4])fig1.canvas.manager.set_window_title('My line plot')fig2,ax2=plt.subplots(figsize=(3,2))ax2.contourf([[1,2], [3,4]])fig2.canvas.manager.set_window_title('My contour plot')fig3,ax3=plt.subplots(figsize=(3,2))ax3.bar(x=[0,1],height=[1,2])plt.show()

thewebagg output is:

Screenshot 2024-12-17 at 17 01 44

which is consistent with the output produced by e.g. theqtagg backend:

Screenshot 2024-12-17 at 17 02 26

PR checklist

@timhoffm
Copy link
Member

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 ofset_label, butset_window_title is preferred overset_label.

@ianthomas23
Copy link
MemberAuthor

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?

Unfortunately it is not that simple. If the windowtitle is not set then the default such as"Figure 1" is used instead from here:

self.set_window_title(f"Figure{num:d}")

regardless of the backend used.

This can be overridden by passing alabel to theFigure constructor, but any subsequent use ofFigure.set_label does not update thetitle. This behaviour is surprising but it is, for good or bad, the same as for other backends such asqtagg.

To demonstrate this use

importmatplotlibasmplmpl.use("qtagg")#mpl.use('webagg')importmatplotlib.pyplotasplt# 1. Set title using set_window_titlefig1,ax1=plt.subplots(figsize=(3,2))fig1.canvas.manager.set_window_title('Using set_window_title')# 2. Set title using label passed to Figure constructorfig2,ax2=plt.subplots(figsize=(3,2),label="Label in constructor")# 3. Using Figure.set_label has no effect on the window titlefig3,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 forqtagg andwebagg here:
Screenshot 2025-01-02 at 14 47 19
Screenshot 2025-01-02 at 14 46 26

So this PR bringswebagg in line with other backends. WhetherFigure.set_label should also update the title (for all backends) would I think be a separate issue for discussion.

@timhoffmtimhoffm added this to thev3.11.0 milestoneJan 7, 2025
@timhoffmtimhoffm merged commit02263ba intomatplotlib:mainJan 7, 2025
35 of 38 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Bug]: canvas.manager.set_window_title does not work to figure withWebAgg backend
3 participants
@ianthomas23@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp