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

Faster title alignment#28300

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
timhoffm merged 2 commits intomatplotlib:mainfromrcomer:empty-titles
May 28, 2024
Merged

Faster title alignment#28300

timhoffm merged 2 commits intomatplotlib:mainfromrcomer:empty-titles
May 28, 2024

Conversation

rcomer
Copy link
Member

@rcomerrcomer commentedMay 25, 2024
edited
Loading

PR summary

  1. Part of the calculation oftop does not depend ontitle, so move it outside the loop.
  2. If no titles have been set, skip this logic entirely.

I usedfig_many.savefig(stream, format='svg', bbox_inches='tight') andfig_many_sharex.savefig(stream, format='svg', bbox_inches='tight') from#26150 as benchmarks.fig_many.savefig ran in ~320-330 ms regardless of this change. Forfig_many_sharex I got

Withmain:

484 ms ± 9.87 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

After (1)

328 ms ± 8.95 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

After (2)

230 ms ± 9.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

PR checklist

@rcomer
Copy link
MemberAuthor

rcomer commentedMay 25, 2024
edited
Loading

I admit I haven't actually figured outhow the first change made the given example faster.

Edit:ax.xaxis.get_ticks_position() returns "unknown" here soax.xaxis.get_tightbbox gets called, but I have not dug any deeper...

@rcomerrcomer marked this pull request as draftMay 26, 2024 07:26
@rcomer
Copy link
MemberAuthor

I think this would benefit from more digging: the fact that there is no measurable time difference withoutsharex suggests that this method ought to be fast and the real problem forsharex is deeper.

@rcomer
Copy link
MemberAuthor

More digging completed#26150 (comment)

Comment on lines +3006 to +3007
xticklabel_top = any(tick.label2.get_visible() for tick in
[ax.xaxis.majorTicks[0], ax.xaxis.minorTicks[0]])
Copy link
MemberAuthor

@rcomerrcomerMay 27, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Directly check the visibility of the tick label as I think that is the most relevant part fromxaxis.get_ticks_position() and will prevent the unnecessary calls toxaxis.get_tightbbox mentioned at#26150 (comment). Only checking the first tick is consistent withget_ticks_position.

There is a question in my mind about what happens if the ticks are pointing outward but unlabelled, but Ithink that could already be an issue with the existing approach as you could have "default" position and outward ticks. Edit: the ticks themselves aren't included inget_tightbbox so actually this makes no difference.

@rcomerrcomer marked this pull request as ready for reviewMay 27, 2024 19:10
@rcomer
Copy link
MemberAuthor

rcomer commentedMay 28, 2024
edited
Loading

I think CodeCov was telling me that we didn't have any tests with a child axes and an automatically positioned title, so I added one.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems good to me. Does it actually speed things up?

@rcomer
Copy link
MemberAuthor

rcomer commentedMay 28, 2024
edited
Loading

Does it actually speed things up?

If I take this example from#26150
fig_many_sharex.savefig(stream, format='svg', bbox_inches='tight')

Withmain I get

477 ms ± 13.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

with this branch

224 ms ± 6.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

That example has no titles though, so we are now just skipping everything. If I add a title to each subplot I get
main

511 ms ± 9.67 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Branch

275 ms ± 6.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

If I add a title to each subplotand move the ticklabels to the top of each subplot, so we do actually need to calculatexaxis.get_tightbbox (but now fewer times)
main

707 ms ± 13.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Branch

464 ms ± 9.57 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
jklymak reacted with thumbs up emoji

@jklymak
Copy link
Member

We have a benchmarking test suite. I wonder if these are caught by it?@QuLogic maintains that - I actually forget where it is...

@rcomer
Copy link
MemberAuthor

We have a benchmarking test suite

This is news to me!

@timhoffmtimhoffm added this to thev3.10.0 milestoneMay 28, 2024
@timhoffmtimhoffm merged commit9a9fce5 intomatplotlib:mainMay 28, 2024
41 of 42 checks passed
@rcomerrcomer deleted the empty-titles branchMay 29, 2024 12:08
@QuLogic
Copy link
Member

We have a benchmarking test suite

This is news to me!

We do; it ishere. However, we don't testbbox_inches='tight' orsharex, and unfortunately, I haven't run the benchmark in a long while now.

rcomer reacted with eyes emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@oscargusoscargusoscargus left review comments

@jklymakjklymakjklymak approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

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

Successfully merging this pull request may close these issues.

5 participants
@rcomer@jklymak@QuLogic@timhoffm@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp