Skip to content
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

Add Bars for more efficient bar plots and improve Bar as well #2893

Merged
merged 9 commits into from
Jul 11, 2022

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Jul 10, 2022

Similar to how we have Line/Lines, the Bars mark uses a PatchCollection for more efficient drawing. (Unlike with Lines, we don't need to reduce the mappable properties). This can have a substantial effect:

x = np.linspace(-3, 3, 1000)
y = np.exp(-(x ** 2))

%time so.Plot(x, y, color=x).add(so.Bar()).save(io.BytesIO())
%time so.Plot(x, y, color=x).add(so.Bars()).save(io.BytesIO())
CPU times: user 2.66 s, sys: 20.3 ms, total: 2.68 s
Wall time: 1.65 s
CPU times: user 918 ms, sys: 12.3 ms, total: 930 ms
Wall time: 397 ms

The default property values for Bars are also a little different: width is set to 1, edges use the patch.linecolor rc parameter, and edge widths are automatically set using the same approach in histplot to scale down for a dense plot.

so.Plot(diamonds, "price").add(so.Bars(), so.Hist())

image

@codecov
Copy link

codecov bot commented Jul 10, 2022

Codecov Report

Merging #2893 (6415872) into master (3180fd7) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2893      +/-   ##
==========================================
+ Coverage   98.19%   98.20%   +0.01%     
==========================================
  Files          69       69              
  Lines       22435    22561     +126     
==========================================
+ Hits        22030    22156     +126     
  Misses        405      405              
Impacted Files Coverage Δ
seaborn/_marks/bars.py 100.00% <100.00%> (ø)
seaborn/_marks/base.py 98.30% <100.00%> (+0.04%) ⬆️
seaborn/_marks/scatter.py 100.00% <100.00%> (ø)
seaborn/objects.py 100.00% <100.00%> (ø)
tests/_marks/test_bars.py 100.00% <100.00%> (ø)
tests/_marks/test_base.py 100.00% <100.00%> (ø)

@mwaskom mwaskom merged commit 3c8447f into master Jul 11, 2022
@mwaskom mwaskom deleted the bar/speed branch July 11, 2022 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant