Skip to content

Improve hexbin performance #7944

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

Merged
merged 2 commits into from
Jan 25, 2017
Merged

Conversation

dstansby
Copy link
Member

A large chunk of time in hexbin is spent binning the data. This PR speeds that up by converting some if statements to matrix multiplication, and reducing the length of the remaining for loops.

I've tested the speedup using the following code:

import matplotlib.pyplot as plt
import numpy as np
import time

for i in range(1, 7):
    x = np.random.rand(10**i)
    y = np.random.rand(10**i)
    start = time.time()
    plt.hexbin(x, y)
    end = time.time()
    print(i, end - start)

Before, this prints

1 0.07006597518920898
2 0.0029900074005126953
3 0.0072820186614990234
4 0.0190579891204834
5 0.19024014472961426
6 1.8048720359802246

After my changes it prints

1 0.06623506546020508
2 0.002410888671875
3 0.006618022918701172
4 0.009796142578125
5 0.1008000373840332
6 0.9016518592834473

so for large arrays there's ~50% speedup.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 25, 2017
@NelleV
Copy link
Member

NelleV commented Jan 25, 2017

Thanks @dstansby !

@NelleV NelleV merged commit 041a9ca into matplotlib:master Jan 25, 2017
@dstansby
Copy link
Member Author

No problem! (as you can probably guess I've been using hexbin quite a bit lately!)

@dstansby dstansby deleted the hexbin-speedup branch February 14, 2017 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy