Skip to content

Commit fb169e5

Browse files
author
evgenii
committed
STYLE: apply ruff / isort auto-formatting on core.py
1 parent 22f12fc commit fb169e5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
Series,
100100
)
101101

102+
import itertools
103+
104+
from matplotlib.collections import LineCollection
105+
102106

103107
def holds_integer(column: Index) -> bool:
104108
return column.inferred_type in {"integer", "mixed-integer"}
@@ -1549,6 +1553,30 @@ def __init__(self, data, **kwargs) -> None:
15491553
self.data = self.data.fillna(value=0)
15501554

15511555
def _make_plot(self, fig: Figure) -> None:
1556+
threshold = 200 # switch when DataFrame has more than this many columns
1557+
can_use_lc = (
1558+
not self._is_ts_plot() # not a TS plot
1559+
and not self.stacked # stacking not requested
1560+
and not com.any_not_none(*self.errors.values()) # no error bars
1561+
and len(self.data.columns) > threshold
1562+
)
1563+
if can_use_lc:
1564+
ax = self._get_ax(0)
1565+
x = self._get_xticks()
1566+
segments = [
1567+
np.column_stack((x, self.data[col].values)) for col in self.data.columns
1568+
]
1569+
base_colors = mpl.rcParams["axes.prop_cycle"].by_key()["color"]
1570+
colors = list(itertools.islice(itertools.cycle(base_colors), len(segments)))
1571+
lc = LineCollection(
1572+
segments,
1573+
colors=colors,
1574+
linewidths=self.kwds.get("linewidth", mpl.rcParams["lines.linewidth"]),
1575+
)
1576+
ax.add_collection(lc)
1577+
ax.margins(0.05)
1578+
return # skip the per-column Line2D loop
1579+
15521580
if self._is_ts_plot():
15531581
data = maybe_convert_index(self._get_ax(0), self.data)
15541582

0 commit comments

Comments
 (0)