11from __future__ import annotations
22
33from dataclasses import replace
4- from typing import TYPE_CHECKING
4+ from typing import TYPE_CHECKING , Sequence , cast
55
66import numpy as np
77
1010if TYPE_CHECKING :
1111 import pandas as pd
1212 from matplotlib .axes import Axes
13+ from matplotlib .projections .polar import PolarAxes
1314
1415 from plotnine .iapi import panel_view
1516 from plotnine .scales .scale import scale
@@ -184,7 +185,8 @@ def setup_panel_params(self, scale_x: scale, scale_y: scale) -> panel_view:
184185 if self .rlim is not None :
185186 self .params ["r_range" ] = tuple (self .rlim )
186187 rlo , rhi = self .rlim
187- breaks , labels = pv .y .breaks , pv .y .labels
188+ breaks = cast ("Sequence[float]" , pv .y .breaks )
189+ labels = pv .y .labels
188190 mask = [rlo <= b <= rhi for b in breaks ]
189191 new_y = replace (
190192 pv .y ,
@@ -287,11 +289,12 @@ def draw(self, axs: list[Axes]) -> None:
287289 arc = self ._arc
288290
289291 for ax in axs :
292+ polar_ax = cast ("PolarAxes" , ax )
290293 # Restrict visible theta range for partial arcs.
291294 if self .end is not None :
292295 theta_lo = min (self .start , self .start + arc )
293296 theta_hi = max (self .start , self .start + arc )
294- ax .set_thetalim (theta_lo , theta_hi )
297+ polar_ax .set_thetalim (theta_lo , theta_hi )
295298
296299 # Inner radius: push the data away from the centre by setting a
297300 # virtual r-origin below r_min. Formula: solve
@@ -306,16 +309,18 @@ def draw(self, axs: list[Axes]) -> None:
306309 r_origin = (r_min - self .inner_radius * r_max ) / (
307310 1.0 - self .inner_radius
308311 )
309- ax .set_rorigin (r_origin )
312+ polar_ax .set_rorigin (r_origin )
310313
311314 # Radial axis label placement.
312315 if self .r_axis_inside is not None :
313316 if isinstance (self .r_axis_inside , bool ):
314317 if self .r_axis_inside :
315318 # Just inside the start angle keeps it out of the data.
316- ax .set_rlabel_position (np .degrees (self .start ) + 10 )
319+ polar_ax .set_rlabel_position (
320+ np .degrees (self .start ) + 10
321+ )
317322 else :
318- ax .set_rlabel_position (
323+ polar_ax .set_rlabel_position (
319324 np .degrees (float (self .r_axis_inside ))
320325 )
321326
0 commit comments