-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: speed up wide DataFrame.line plots by using a single LineCollection #61764
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
EvMossan
wants to merge
5
commits into
pandas-dev:main
Choose a base branch
from
EvMossan:plot-linecollection-speedup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb169e5
STYLE: apply ruff / isort auto-formatting on core.py
cd3bd4d
TST: use default_rng to satisfy Ruff NPY002
f756948
DOC: add Performance improvement bullet for LineCollection speed-up
8ec4218
TST: skip speedup test when matplotlib is not installed
0febdd9
DOC: whatsnew entry for LineCollection speed-up
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
pandas/tests/plotting/frame/test_linecollection_speedup.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Ensure wide DataFrame.line plots use a single LineCollection | ||
instead of one Line2D per column (PR #61764). | ||
""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import pandas as pd | ||
|
||
# Skip this entire module if matplotlib is not installed | ||
mpl = pytest.importorskip("matplotlib") | ||
plt = pytest.importorskip("matplotlib.pyplot") | ||
from matplotlib.collections import LineCollection | ||
|
||
|
||
def test_linecollection_used_for_wide_dataframe(): | ||
rng = np.random.default_rng(0) | ||
df = pd.DataFrame(rng.standard_normal((10, 201)).cumsum(axis=0)) | ||
|
||
ax = df.plot(legend=False) | ||
|
||
# exactly one LineCollection, and no Line2D artists | ||
assert sum(isinstance(c, LineCollection) for c in ax.collections) == 1 | ||
assert len(ax.lines) == 0 | ||
|
||
plt.close(ax.figure) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to have a special casing like this because it's difficult to maintain parity between a "fast path" and the existing path.
Is there a way to refactor our plotting here to generalize the plotting to this form rather than the iterative approach below?