Skip to content

BUG: Fixed issue with bar plots not stacking correctly when 'stacked' and 'subplots' are used together #61340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

eicchen02
Copy link

@eicchen02 eicchen02 commented Apr 23, 2025

Added check for when stacked and subplots are used in conjunction for bar plots. And logic dictating offsets for individual subplots to account for plots with non-concurrent columns being graphed.

Currently, does not take into account column order in subplot entry (eg: (A, B) vs (B, A)) when stacking

Comment on lines +1935 to +1941
self.subplots: list[Any]
if self.subplots:
subplots_flag = 1
else:
subplots_flag = 0

if subplots_flag & self.stacked:
Copy link
Member

@mroeschke mroeschke Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.subplots: list[Any]
if self.subplots:
subplots_flag = 1
else:
subplots_flag = 0
if subplots_flag & self.stacked:
if self.subplots and self.stacked:

Comment on lines +1942 to +1951
sub_range = range(len(self.subplots))
ss_temp = {
x: self.subplots[x] for x in sub_range if len(self.subplots[x]) > 1
}
for k, v in ss_temp.items():
for x in v:
_stacked_subplots_ind.setdefault(int(x), k)

_stacked_subplots_offsets.append([0, 0])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sub_range = range(len(self.subplots))
ss_temp = {
x: self.subplots[x] for x in sub_range if len(self.subplots[x]) > 1
}
for k, v in ss_temp.items():
for x in v:
_stacked_subplots_ind.setdefault(int(x), k)
_stacked_subplots_offsets.append([0, 0])
for i, sub_plot in enumerate(self.subplots):
if len(sub_plot) <= 1:
continue
for plot in sub_plot:
_stacked_subplots_ind[int(plot)] = i
_stacked_subplots_offsets.append([0, 0])

Comment on lines +686 to +696
@pytest.fixture(scope="class")
def BSS_data():
return np.random.default_rng(3).integers(0, 100, 5)


@pytest.fixture(scope="class")
def BSS_df(BSS_data) -> DataFrame:
BSS_df = DataFrame(
{"A": BSS_data, "B": BSS_data[::-1], "C": BSS_data[0], "D": BSS_data[-1]}
)
return BSS_df
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@pytest.fixture(scope="class")
def BSS_data():
return np.random.default_rng(3).integers(0, 100, 5)
@pytest.fixture(scope="class")
def BSS_df(BSS_data) -> DataFrame:
BSS_df = DataFrame(
{"A": BSS_data, "B": BSS_data[::-1], "C": BSS_data[0], "D": BSS_data[-1]}
)
return BSS_df
@pytest.fixture
def BSS_data():
return np.random.default_rng(3).integers(0, 100, 5)
@pytest.fixture
def BSS_df(BSS_data) -> DataFrame:
return DataFrame(
{"A": BSS_data, "B": BSS_data[::-1], "C": BSS_data[0], "D": BSS_data[-1]}
)

Also what's the BBS abbreviation? It would be better to use a clearer name

sliced_df = subplot_sliced_by_source[i]
if i == 0:
# Checks that the bar chart starts y=0
assert (sliced_df["y_coord"] == 0).all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert (sliced_df["y_coord"] == 0).all
assert (sliced_df["y_coord"] == 0).all()

?

)


class TestBarSubplotStacked:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the test class? We're moving away from using this style

@mroeschke mroeschke added the Visualization plotting label Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: df.plot() "Subplots" changes behavior of how values are stacked using the "Stacked" property
2 participants