FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't modify Axes property cycle in stackplot by QuLogic · Pull Request #24026 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 8 additions & 5 deletions lib/matplotlib/stackplot.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
Expand Up @@ -6,6 +6,8 @@
(https://stackoverflow.com/users/66549/doug)
"""

import itertools

import numpy as np

from matplotlib import _api
Expand Down Expand Up @@ -70,7 +72,9 @@ def stackplot(axes, x, *args,

labels = iter(labels)
if colors is not None:
axes.set_prop_cycle(color=colors)
colors = itertools.cycle(colors)
else:
colors = (axes._get_lines.get_next_color() for _ in y)

# Assume data passed has not been 'stacked', so stack it here.
# We'll need a float buffer for the upcoming calculations.
Expand Down Expand Up @@ -108,17 +112,16 @@ def stackplot(axes, x, *args,
stack += first_line

# Color between x = 0 and the first array.
color = axes._get_lines.get_next_color()
coll = axes.fill_between(x, first_line, stack[0, :],
facecolor=color, label=next(labels, None),
facecolor=next(colors), label=next(labels, None),
**kwargs)
coll.sticky_edges.y[:] = [0]
r = [coll]

# Color between array i-1 and array i
for i in range(len(y) - 1):
color = axes._get_lines.get_next_color()
r.append(axes.fill_between(x, stack[i, :], stack[i + 1, :],
facecolor=color, label=next(labels, None),
facecolor=next(colors),
label=next(labels, None),
**kwargs))
return r
5 changes: 3 additions & 2 deletions lib/matplotlib/tests/test_axes.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
Expand Up @@ -2851,10 +2851,11 @@ def test_stackplot():
ax.set_xlim((0, 10))
ax.set_ylim((0, 70))

# Reuse testcase from above for a labeled data test
# Reuse testcase from above for a test with labeled data and with colours
# from the Axes property cycle.
data = {"x": x, "y1": y1, "y2": y2, "y3": y3}
fig, ax = plt.subplots()
ax.stackplot("x", "y1", "y2", "y3", data=data)
ax.stackplot("x", "y1", "y2", "y3", data=data, colors=["C0", "C1", "C2"])
ax.set_xlim((0, 10))
ax.set_ylim((0, 70))

Expand Down

Back | FazBrowse Home | New Git URL