Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Figure.colorbar triggers colormesh deprecation #23614

Closed
@mroeschke

Description

@mroeschke

Bug summary

xref #21723

In pandas, we have this matplotlib code calling Figure.colorbar which is triggering the colormesh deprecation:

Auto-removal of grids by pcolor() and pcolormesh() is deprecated since 3.5 and will be removed two minor releases later; please call grid(False) first.

https://github.com/pandas-dev/pandas/blob/03b4095f9de08af16db9698f15161b5a13a42286/pandas/plotting/_matplotlib/core.py#L1175-L1176

And calling ax.grid(False) does not address the deprecation

diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py
index ee7493813f..69c749e84b 100644
--- a/pandas/plotting/_matplotlib/core.py
+++ b/pandas/plotting/_matplotlib/core.py
@@ -1172,6 +1172,7 @@ class PlanePlot(MPLPlot, ABC):
         # GH33389, if ax is used multiple times, we should always
         # use the last one which contains the latest information
         # about the ax
+        ax.grid(False)
         img = ax.collections[-1]
         return self.fig.colorbar(img, ax=ax, **kwds)

Code for reproduction

https://github.com/pandas-dev/pandas/blob/03b4095f9de08af16db9698f15161b5a13a42286/pandas/plotting/_matplotlib/core.py#L1175-L1176

Actual outcome

Auto-removal of grids by pcolor() and pcolormesh() is deprecated since 3.5 and will be removed two minor releases later; please call grid(False) first.

Expected outcome

No deprecation warning.

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions