From 2c1b2a91d78b9eb921751d13f42cc02f73471c5b Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Mon, 16 Dec 2024 15:04:45 +0300 Subject: [PATCH] Fix axis_ticks_length for the x-axis --- doc/changelog.qmd | 3 +++ plotnine/themes/themeable.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/changelog.qmd b/doc/changelog.qmd index 657922196..cdc83d3b3 100644 --- a/doc/changelog.qmd +++ b/doc/changelog.qmd @@ -23,6 +23,9 @@ title: Changelog if the `y` aesthetic is mapped to datetime column in another layer. +- Fixed bug for matplotlib>3.10 where the `axis_ticks_length` for the x-axis + had no effect. + ## v0.14.3 (2024-11-26) [![](https://zenodo.org/badge/DOI/10.5281/zenodo.14224336.svg)](https://doi.org/10.5281/zenodo.14224336) diff --git a/plotnine/themes/themeable.py b/plotnine/themes/themeable.py index a20a489cb..f5c1fb3db 100644 --- a/plotnine/themes/themeable.py +++ b/plotnine/themes/themeable.py @@ -1037,9 +1037,21 @@ class axis_ticks_major_x(MixinSequenceOfValues): def apply_ax(self, ax: Axes): super().apply_ax(ax) params = ax.xaxis.get_tick_params(which="major") - if not params.get("left", False): + + # TODO: Remove this code when the minimum matplotlib >= 3.10.0, + # and use the commented one below it + import matplotlib as mpl + from packaging import version + + vinstalled = version.parse(mpl.__version__) + v310 = version.parse("3.10.0") + name = "bottom" if vinstalled >= v310 else "left" + if not params.get(name, False): return + # if not params.get("bottom", False): + # return + tick_params = {} properties = self.properties with suppress(KeyError):