Skip to content

Commit

Permalink
first attempt at implementing ha adjustment for facet strip_text_x
Browse files Browse the repository at this point in the history
  • Loading branch information
John Henderson committed Sep 5, 2024
1 parent 4159f95 commit 620ae07
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions plotnine/_mpl/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,31 @@ def draw(self, renderer: RendererBase):
self.patch.set_transform(info.ax.transAxes)
self.patch.set_mutation_scale(0)

info.ha = "right"
margin = 0.05

# Put text in center of patch
self._x = l + w / 2
if isinstance(info.ha, str):
lookup = {
"left": 0.0,
"center": 0.5,
"right": 1.0,
}
f = lookup[info.ha]
anchor = info.ha
if anchor == "right":
margin = -margin
else:
f = info.ha
anchor = "left" if info.ha < 0.5 else "right"

self._x = l + (w * f) + (w * margin)
self._y = b + h / 2

# "anchor" aligns before rotation so the right-strip get properly
# centered text
self.set_rotation_mode("anchor")
self.set_horizontalalignment("center") # right-strip
self.set_horizontalalignment(anchor) # right-strip
self.set_verticalalignment("center_baseline") # top-strip

# Draw spatch
Expand Down

0 comments on commit 620ae07

Please sign in to comment.