Skip to content

Commit

Permalink
Fix spacing issue in _spacing function
Browse files Browse the repository at this point in the history
  • Loading branch information
juhabae committed Nov 17, 2024
1 parent b4e5f8d commit 9c210a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion seaborn/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,10 @@ def get_order(var):
view_width = view_df["width"]
else:
view_width = 0.8 # TODO what default?
spacing = scales[orient]._spacing(view_df.loc[view_idx, orient])
spacing = scales[orient]._spacing(
view_df.loc[view_idx, orient],
groupby=view_df["group"]
)
width.loc[view_idx] = view_width * spacing
df["width"] = width

Expand Down
17 changes: 10 additions & 7 deletions seaborn/_core/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ def set_default_locators_and_formatters(self, axis):

return InternalScale(name, (forward, inverse))

def _spacing(self, x: Series) -> float:
space = self._spacer(x)
if np.isnan(space):
# This happens when there is no variance in the orient coordinate data
# Not exactly clear what the right default is, but 1 seems reasonable?
return 1
return space
def _spacing(self, x: Series, groupby: Optional[Series] = None) -> float:
if groupby is not None:
grouped = x.groupby(groupby)
spaces = grouped.apply(lambda group: self._spacer(group))
return spaces.min()
else:
space = self._spacer(x)
if np.isnan(space):
return 1
return space

def _setup(
self, data: Series, prop: Property, axis: Axis | None = None,
Expand Down

0 comments on commit 9c210a1

Please sign in to comment.