Skip to content

Commit 7a26a47

Browse files
iangowclaude
andcommitted
Add theta_labels parameter to coord_radial for full-circle theta axis labels
Partial-arc plots already show theta tick labels on the outer edge. Full-circle charts (pac-man, coxcomb) suppress them by default. theta_labels=True opts a full-circle plot into the same behaviour, passing scale breaks through to Matplotlib's PolarAxes which places and rotates them outside the circle automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 954dbbc commit 7a26a47

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

plotnine/coords/coord_radial.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class coord_radial(coord_polar):
6363
Data-space limits for the r axis as ``(lo, hi)``. Only data within
6464
this range is shown; equivalent to zooming on the radial axis.
6565
``None`` (default) uses the full data range.
66+
theta_labels :
67+
If ``True``, show theta axis tick labels on the outer edge of the
68+
circle for full-circle plots, using the breaks and labels from the
69+
theta scale. Default ``False``. Partial-arc plots always show
70+
theta labels (filtered to the visible arc) regardless of this flag.
6671
"""
6772

6873
def __init__(
@@ -77,6 +82,7 @@ def __init__(
7782
rotate_angle: bool = False,
7883
thetalim: tuple[float, float] | None = None,
7984
rlim: tuple[float, float] | None = None,
85+
theta_labels: bool = False,
8086
) -> None:
8187
super().__init__(
8288
theta=theta,
@@ -90,6 +96,7 @@ def __init__(
9096
self.rotate_angle = rotate_angle
9197
self.thetalim = thetalim
9298
self.rlim = rlim
99+
self.theta_labels = theta_labels
93100

94101
# ------------------------------------------------------------------
95102
# Panel params
@@ -137,15 +144,17 @@ def setup_panel_params(self, scale_x: scale, scale_y: scale) -> panel_view:
137144
arc_lo = min(self.start, self.start + arc)
138145
arc_hi = max(self.start, self.start + arc)
139146

140-
# For partial arcs only: convert data-space theta breaks to radian
141-
# positions and restore them as theta axis tick labels on the outer edge.
142-
# Full-circle charts (pac-man, coxcomb) keep breaks=[] as set by super().
147+
# Convert data-space theta breaks to radian positions and restore them
148+
# as theta axis tick labels on the outer edge. Always done for partial
149+
# arcs; for full circles only when theta_labels=True (opt-in, so that
150+
# pac-man / coxcomb charts keep breaks=[] as set by super()).
143151
x_updates: dict = {}
144-
if theta_breaks and arc_lo is not None:
152+
if theta_breaks and (arc_lo is not None or self.theta_labels):
145153
radian_pos = list(self._to_radians(np.asarray(theta_breaks, dtype=float)))
146-
keep = [arc_lo <= r <= arc_hi for r in radian_pos]
147-
radian_pos = [r for r, k in zip(radian_pos, keep) if k]
148-
theta_labels = [l for l, k in zip(theta_labels, keep) if k]
154+
if arc_lo is not None:
155+
keep = [arc_lo <= r <= arc_hi for r in radian_pos]
156+
radian_pos = [r for r, k in zip(radian_pos, keep) if k]
157+
theta_labels = [l for l, k in zip(theta_labels, keep) if k]
149158
x_updates["breaks"] = radian_pos
150159
x_updates["labels"] = theta_labels
151160

0 commit comments

Comments
 (0)