From c3678ec2b2a3398392362a5ff9df5cde00478c8d Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Thu, 13 Jun 2024 22:21:06 +0300 Subject: [PATCH] Fix layers 3 & above overlapping the axis lines fixes #798 --- doc/changelog.qmd | 4 ++++ plotnine/themes/themeable.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/changelog.qmd b/doc/changelog.qmd index 1b6869cb3..11cde42a7 100644 --- a/doc/changelog.qmd +++ b/doc/changelog.qmd @@ -15,6 +15,10 @@ title: Changelog - [](:class:`~plotnine.geom_text`) has gained new aesthetics `fontvariant` and `fontstretch`. +### Bug Fixes + +- Fix layers 3 and above not to overlap the axis lines if there are any + ({{< issue 798 >}}). ## v0.13.6 (2024-05-09) diff --git a/plotnine/themes/themeable.py b/plotnine/themes/themeable.py index 92cf8d52b..f222a00cf 100644 --- a/plotnine/themes/themeable.py +++ b/plotnine/themes/themeable.py @@ -893,8 +893,13 @@ class axis_line_x(themeable): def apply_ax(self, ax: Axes): super().apply_ax(ax) + properties = self.properties + # MPL has a default zorder of 2.5 for spines + # so layers 3+ would be drawn on top of the spines + if "zorder" not in properties: + properties["zorder"] = 10000 ax.spines["top"].set_visible(False) - ax.spines["bottom"].set(**self.properties) + ax.spines["bottom"].set(**properties) def blank_ax(self, ax: Axes): super().blank_ax(ax) @@ -916,8 +921,13 @@ class axis_line_y(themeable): def apply_ax(self, ax: Axes): super().apply_ax(ax) + properties = self.properties + # MPL has a default zorder of 2.5 for spines + # so layers 3+ would be drawn on top of the spines + if "zorder" not in properties: + properties["zorder"] = 10000 ax.spines["right"].set_visible(False) - ax.spines["left"].set(**self.properties) + ax.spines["left"].set(**properties) def blank_ax(self, ax: Axes): super().blank_ax(ax)