ENH: speed up wide DataFrame.line plots by using a single LineCollection #61764
+56
−0
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.
What does this PR change?
DataFrame.plot(kind="line")
when the frame is “wide”.If the DataFrame has > 200 columns, is not a time-series plot, has
no stacking and no error bars, we now draw everything with a single
matplotlib.collections.LineCollection
instead of oneLine2D
per column.cases above.
Performance numbers
df.plot(legend=False)
Benchmarked on pandas 3.0.0.dev0+2183.g94ff63adb2, matplotlib 3.10.3, NumPy 2.2.6
Notes
DatetimeIndex
plots—those remain on the original per-column path. A follow-up could combineLineCollection
with thex_compat=True
workaround (see #61398) to similarly speed up time-series plots.> 200
columns) is a heuristic and can be tuned in review.DataFrame.plot
usingLineCollection
#61532pytest pandas/tests/plotting -q
)pre-commit run --all-files
)doc/source/whatsnew/v3.0.0.rst
cc @shadnikn @arthurlw – happy to take any feedback 🙂