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
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.
The text was updated successfully, but these errors were encountered:
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
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.
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:
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.The text was updated successfully, but these errors were encountered: