Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions plotnine/_mpl/layout_manager/_plot_side_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,20 @@ def axis_title_clearance(self) -> float:
raise PlotnineError("Side has no axis title") from err

@property
def _axis_primary_extent(self) -> float:
def _axis_ticks_and_text(self) -> float:
"""
Outward extent of a moved axis's ticks and tick labels, figure space
Outward extent of this side's axis ticks and tick labels, figure space

This is the part of a moved axis that sits next to the panel; the
axis title is excluded. Zero on sides whose axis is in its default
position.
The axis title is excluded. Computed from the items present on the
side, identically for all four sides; zero on a side with no axis.
"""
return 0

# Typed default so strip_band_offset type-checks; concrete sides redeclare.
strip_text: float = 0
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")

def strip_band_offset(self, member: Literal["strip", "axis"]) -> float:
"""
Outward offset for one member of a shared strip/axis band

When a moved axis and a facet strip occupy the same side, the band is
When a facet strip and an axis occupy the same side, the band is
ordered from the panel outward. `strip_placement` chooses the order:

"inside": panel | strip | ticks+labels | title
Expand All @@ -171,20 +167,17 @@ def strip_band_offset(self, member: Literal["strip", "axis"]) -> float:
consumed per artist in its own coordinate system: the title in figure
space, the tick labels in axes fractions, the spine in points.

The offset is zero unless the side has both a strip and a moved axis.
Bottom/left sides leave `_axis_primary_extent` at zero (a strip there
would share the side with the *default* axis, which the facet API does
not yet expose), so this returns zero for them.
The offset is zero unless the side carries both a strip and an axis.
"""
strip = self.strip_text
primary = self._axis_primary_extent
if not (strip and primary):
strip_breadth: float = self.strip_text # pyright: ignore[reportAttributeAccessIssue]
axis_breadth = self._axis_ticks_and_text
if not (strip_breadth and axis_breadth):
return 0
placement = self.items.plot.theme.getp("strip_placement")
if placement == "inside":
return 0 if member == "strip" else strip
return 0 if member == "strip" else strip_breadth
# "outside"
return primary if member == "strip" else 0
return axis_breadth if member == "strip" else 0


class left_space(_plot_side_space):
Expand Down Expand Up @@ -435,10 +428,6 @@ def _calculate(self):
if adjustment > 0:
self.plot_margin += adjustment

@property
def _axis_primary_extent(self) -> float:
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")

@property
def axis_title_clearance(self) -> float:
"""
Expand Down Expand Up @@ -600,10 +589,6 @@ def _calculate(self):
if adjustment > 0:
self.plot_margin += adjustment

@property
def _axis_primary_extent(self) -> float:
return self.sum_incl("axis_ticks") - self.sum_upto("axis_text")

@property
def axis_title_clearance(self) -> float:
"""
Expand Down
Loading