Skip to content

Commit ccd28bf

Browse files
committed
fix guide_axis_theta: use 'auto' mode so angle is relative to tangent
In Matplotlib, ThetaTick has two label-rotation modes: ('default', N) — absolute N degrees (what tick_params(labelrotation=N) sets) ('auto', N) — tangential direction + N degrees offset ggplot2's guide_axis_theta(angle=0) means labels tangential to the arc (0° offset from the tangent), not horizontal. Patching tick._labelrotation directly is the only way to set 'auto' mode with a user-angle offset since ax.tick_params() always sets 'default' mode.
1 parent 140e817 commit ccd28bf

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

plotnine/coords/coord_radial.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,13 @@ def setup_ax(
335335
if self.theta_labels or self.end is not None:
336336
ax.tick_params(axis="x", pad=self.theta_label_pad)
337337
if (angle := self._theta_guide_angle(theme)) is not None:
338-
ax.tick_params(axis="x", labelrotation=angle)
339-
for label in ax.get_xticklabels():
340-
label.set_rotation(angle)
341-
label.set_rotation_mode("anchor")
338+
# Use Matplotlib's 'auto' mode so labels orient tangentially
339+
# to the arc, with `angle` as an offset — matching ggplot2's
340+
# guide_axis_theta() semantics where angle=0 means tangential.
341+
# ax.tick_params(labelrotation=...) always sets 'default' mode
342+
# (absolute degrees), so we patch each tick directly instead.
343+
for tick in ax.xaxis.get_major_ticks():
344+
tick._labelrotation = ("auto", angle)
342345
# Allow geom_text labels to extend past the polar axes bounding box
343346
# (e.g. spoke labels placed just beyond the outermost bar tip).
344347
for text in ax.texts:

0 commit comments

Comments
 (0)