8000 [ENH]: Speed up Axes.bar through the use of PatchCollection · Issue #22976 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[ENH]: Speed up Axes.bar through the use of PatchCollection #22976

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
timhoffm opened this issue May 4, 2022 · 2 comments
Open

[ENH]: Speed up Axes.bar through the use of PatchCollection #22976

timhoffm opened this issue May 4, 2022 · 2 comments

Comments

@timhoffm
Copy link
Member
timhoffm commented May 4, 2022

Problem

Bar charts are relatively slow because each bar is a separate Rectangle. From a quick check, this scales really linearly with the number of bars N:

N = [30, 100, 300, 1000, 3000, 10000]
t = [29, 103, 290, 951, 2860, 9790]  # in ms for `plt.bar(x, y)`

While one should not have too many bars in a plot, possibly up to 1000 could be reasonable. The time delay is still okish herem but if e.g. I have multiple subplots, it can become noticable.

Proposed solution

One possible solution is to replace the single Rectangles by a PatchCollection (inspired by #20092).
For backward-compatibility, we'd have to intoduces this gradually similar to what has been done in hist(..., histtype=...): Add a parameter to make the created Artist configurable. The default stays on isolated bars, using a collection is opt-in. The default can be switched later.

@timhoffm timhoffm mentioned this issue May 4, 2022
11 tasks
@timhoffm timhoffm changed the title [ENH]: Speed up Axes.bar through the use of Patch collection [ENH]: Speed up Axes.bar through the use of PatchCollection May 4, 2022
@QuLogic
Copy link
Member
QuLogic commented Dec 8, 2023

I had a look at #20092 and copied it back to main. After fixing a larger issue, I think the main reason for the test failures is that the collection doesn't seem to do path snapping like the individual rectangles do, even though it seems like it should.

@timhoffm
Copy link
Member Author

MHO it’s viable to explicitly set snapping in the tests to be able to reuse existing reference images.

We could also activate snapping when creating the collection in bar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0