Skip to content

Commit 2b3e1cc

Browse files
iangowhas2k1
authored andcommitted
Move polar border blanking to themeable
1 parent 7a65e28 commit 2b3e1cc

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

plotnine/ggplot.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,6 @@ def _draw_panel_borders(self):
520520
# grid lines below the borders. We leave ax.patch for the
521521
# background only.
522522
if self.theme.T.is_blank("panel_border"):
523-
# For PolarAxes the default circular spine is separate from the
524-
# panel border Rectangle; hide it explicitly when blank.
525-
for ax in self.axs:
526-
if "polar" in ax.spines:
527-
ax.spines["polar"].set_visible(False)
528523
return
529524

530525
from matplotlib.patches import Rectangle

plotnine/themes/themeable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,11 @@ def blank_figure(self, figure: Figure, targets: ThemeTargets):
17111711
for rect in targets.panel_border:
17121712
rect.set_visible(False)
17131713

1714+
def blank_ax(self, ax: Axes):
1715+
super().blank_ax(ax)
1716+
if "polar" in ax.spines:
1717+
ax.spines["polar"].set_visible(False)
1718+
17141719

17151720
class plot_background(themeable):
17161721
"""

tests/test_theme.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import matplotlib as mpl
44
import pytest
5+
from matplotlib import pyplot as plt
56
from packaging import version
67

78
from plotnine import (
@@ -34,6 +35,7 @@
3435
theme_xkcd,
3536
)
3637
from plotnine.data import mtcars
38+
from plotnine.themes.themeable import panel_border
3739

3840
LT_MPL310 = version.parse(mpl.__version__) < version.parse("3.10")
3941
IS_CI = bool(os.environ.get("CI"))
@@ -111,6 +113,17 @@ def test_add_element_blank():
111113
assert theme3 == theme4 # blanking cleans the slate
112114

113115

116+
def test_blank_panel_border_hides_polar_spine():
117+
th = panel_border(element_blank())
118+
fig, ax = plt.subplots(subplot_kw={"projection": "polar"})
119+
120+
try:
121+
th.blank_ax(ax)
122+
assert not ax.spines["polar"].get_visible()
123+
finally:
124+
plt.close(fig)
125+
126+
114127
def test_element_line_dashed_capstyle():
115128
p = ggplot(mtcars, aes(x="wt", y="mpg")) + theme(
116129
panel_grid=element_line(

0 commit comments

Comments
 (0)