Skip to content

Commit 0d9f5da

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

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
@@ -1921,6 +1921,19 @@ def _make_plot(self, fig: Figure) -> None:
19211921
K = self.nseries
19221922

19231923
data = self.data.fillna(0)
1924+
1925+
_stacked_subplots_ind_dict = {}
1926+
_stacked_subplots_offsets = []
1927+
1928+
if self.subplots != False & self.stacked:
1929+
# _stacked_subplots_list = [sorted(x) for x in self.subplots if len(x) > 1]
1930+
temp_ss_dict = {x: self.subplots[x] for x in range(len(self.subplots)) if len(self.subplots[x]) > 1}
1931+
for k, v in temp_ss_dict.items():
1932+
for x in v:
1933+
_stacked_subplots_ind_dict.setdefault(int(x), k)
1934+
1935+
_stacked_subplots_offsets.append([0,0])
1936+
19241937
for i, (label, y) in enumerate(self._iter_data(data=data)):
19251938
ax = self._get_ax(i)
19261939
kwds = self.kwds.copy()
@@ -1946,7 +1959,33 @@ def _make_plot(self, fig: Figure) -> None:
19461959
start = start + self._start_base
19471960

19481961
kwds["align"] = self._align
1949-
if self.subplots:
1962+
1963+
try:
1964+
offset_index = _stacked_subplots_ind_dict[i]
1965+
_stacked_subplots_flag = 1
1966+
except:
1967+
_stacked_subplots_flag = 0
1968+
1969+
if _stacked_subplots_flag:
1970+
mask = y >= 0
1971+
pos_prior, neg_prior = _stacked_subplots_offsets[offset_index]
1972+
start = np.where(mask, pos_prior, neg_prior) + self._start_base
1973+
w = self.bar_width / 2
1974+
rect = self._plot(
1975+
ax,
1976+
self.ax_pos + w,
1977+
y,
1978+
self.bar_width,
1979+
start=start,
1980+
label=label,
1981+
log=self.log,
1982+
**kwds,
1983+
)
1984+
pos_new = pos_prior + np.where(mask, y, 0)
1985+
neg_new = neg_prior + np.where(mask, 0, y)
1986+
_stacked_subplots_offsets[offset_index] = [pos_new, neg_new]
1987+
1988+
elif self.subplots:
19501989
w = self.bar_width / 2
19511990
rect = self._plot(
19521991
ax,

0 commit comments

Comments
 (0)