Skip to content

Commit 7643422

Browse files
committed
Completed function fix (order of subplot input does not matter, need clarification if it matters)
1 parent eec5c94 commit 7643422

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,19 @@ def _make_plot(self, fig: Figure) -> None:
19281928
K = self.nseries
19291929

19301930
data = self.data.fillna(0)
1931+
1932+
_stacked_subplots_ind_dict = {}
1933+
_stacked_subplots_offsets = []
1934+
1935+
if self.subplots != False & self.stacked:
1936+
# _stacked_subplots_list = [sorted(x) for x in self.subplots if len(x) > 1]
1937+
temp_ss_dict = {x: self.subplots[x] for x in range(len(self.subplots)) if len(self.subplots[x]) > 1}
1938+
for k, v in temp_ss_dict.items():
1939+
for x in v:
1940+
_stacked_subplots_ind_dict.setdefault(int(x), k)
1941+
1942+
_stacked_subplots_offsets.append([0,0])
1943+
19311944
for i, (label, y) in enumerate(self._iter_data(data=data)):
19321945
ax = self._get_ax(i)
19331946
kwds = self.kwds.copy()
@@ -1953,7 +1966,33 @@ def _make_plot(self, fig: Figure) -> None:
19531966
start = start + self._start_base
19541967

19551968
kwds["align"] = self._align
1956-
if self.subplots:
1969+
1970+
try:
1971+
offset_index = _stacked_subplots_ind_dict[i]
1972+
_stacked_subplots_flag = 1
1973+
except:
1974+
_stacked_subplots_flag = 0
1975+
1976+
if _stacked_subplots_flag:
1977+
mask = y >= 0
1978+
pos_prior, neg_prior = _stacked_subplots_offsets[offset_index]
1979+
start = np.where(mask, pos_prior, neg_prior) + self._start_base
1980+
w = self.bar_width / 2
1981+
rect = self._plot(
1982+
ax,
1983+
self.ax_pos + w,
1984+
y,
1985+
self.bar_width,
1986+
start=start,
1987+
label=label,
1988+
log=self.log,
1989+
**kwds,
1990+
)
1991+
pos_new = pos_prior + np.where(mask, y, 0)
1992+
neg_new = neg_prior + np.where(mask, 0, y)
1993+
_stacked_subplots_offsets[offset_index] = [pos_new, neg_new]
1994+
1995+
elif self.subplots:
19571996
w = self.bar_width / 2
19581997
rect = self._plot(
19591998
ax,

0 commit comments

Comments
 (0)