From 0dd352404d58c22b7d8e90dea5457048f74a938c Mon Sep 17 00:00:00 2001 From: Abel Tavares Date: Sun, 14 Apr 2024 09:52:01 +0100 Subject: [PATCH] BUG: Series.plot(kind="pie") does not respect ylabel argument --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/plotting/_matplotlib/core.py | 3 --- pandas/tests/plotting/frame/test_frame.py | 2 +- pandas/tests/plotting/test_series.py | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index c77348b365370..d7110b446d327 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -42,6 +42,7 @@ Other enhancements - :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) - :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) - :meth:`Series.cummin` and :meth:`Series.cummax` now supports :class:`CategoricalDtype` (:issue:`52335`) +- :meth:`Series.plot` now correctly handle the ``ylabel`` parameter for pie charts, allowing for explicit control over the y-axis label (:issue:`58239`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 38a75e741d60e..fffeb9b82492f 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -2077,9 +2077,6 @@ def _make_plot(self, fig: Figure) -> None: for i, (label, y) in enumerate(self._iter_data(data=self.data)): ax = self._get_ax(i) - if label is not None: - label = pprint_thing(label) - ax.set_ylabel(label) kwds = self.kwds.copy() diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index c30cb96fef252..adb56a40b0071 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -1629,7 +1629,7 @@ def test_pie_df_subplots(self): for ax in axes: _check_text_labels(ax.texts, df.index) for ax, ylabel in zip(axes, df.columns): - assert ax.get_ylabel() == ylabel + assert ax.get_ylabel() == "" def test_pie_df_labels_colors(self): df = DataFrame( diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 9fbc20e10f5c1..54f09c7007330 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -378,7 +378,7 @@ def test_pie_series(self): ) ax = _check_plot_works(series.plot.pie) _check_text_labels(ax.texts, series.index) - assert ax.get_ylabel() == "YLABEL" + assert ax.get_ylabel() == "" def test_pie_series_no_label(self): series = Series(