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

Paths is surprisingly slow #2881

Open
mwaskom opened this issue Jun 27, 2022 · 0 comments
Open

Paths is surprisingly slow #2881

mwaskom opened this issue Jun 27, 2022 · 0 comments

Comments

@mwaskom
Copy link
Owner

mwaskom commented Jun 27, 2022

n = 5000
segments = []
for i in range(n):
    segments.append(
        np.column_stack([
            np.arange(10),
            np.linspace(0, i, 10)
        ])
    )

df = pd.concat([
    pd.DataFrame(xys, columns=["x", "y"]).assign(i=i)
    for i, xys in enumerate(segments)
], ignore_index=True)

Pure matplotlib version:

%%timeit -n 3
f = mpl.figure.Figure()
ax = f.subplots()
ax.add_collection(mpl.collections.LineCollection(segments))
ax.autoscale_view()
f.savefig(io.BytesIO(), dpi=100)
300 ms ± 8.12 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)

Seaborn version:

%%timeit -n 3
so.Plot(df, "x", "y", group="i").add(so.Paths()).save(io.BytesIO(), dpi=100)
1.22 s ± 240 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)

There is an additional cost to adding colors that is not present in the matplotlib version

%%timeit -n 3
f = mpl.figure.Figure()
ax = f.subplots()
ax.add_collection(mpl.collections.LineCollection(segments, array=np.arange(n)))
ax.autoscale_view()
f.savefig(io.BytesIO(), dpi=100)
307 ms ± 5.95 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)

vs.

%%timeit -n 3
so.Plot(df, "x", "y", color="i").add(so.Paths()).save(io.BytesIO(), dpi=100)
3.24 s ± 264 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)

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

1 participant