Skip to content

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

Closed

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

Activity

  1. timhoffm commented on Aug 14, 2022

    @timhoffm
    Member

    Please provide a minimal executable (pandas) example that displays the behavior.

    It seems that for some reason the colorbar axes got a grid, which is a bit unusual. We need the example to see how you are setting up the figure and be able to trace what is happening.


    Internal note: The warning is triggered via

    self.solids = self.ax.pcolormesh(
    . But we have to find out why the colorbar axes has a grid.

  2. oscargus commented on Aug 14, 2022

    @oscargus
    Member

    I believe that this was fixed in #22216 and will be in 3.6.0.

    Most likely you have a style that sets the grid to be True.

  3. oscargus commented on Aug 30, 2022

    @oscargus
    Member

    @mroeschke can you please try with the 3.6 rc and see if this is still an issue?

  4. mroeschke commented on Aug 30, 2022

    @mroeschke
    Author

    Sorry for the delay in responding. I just tested this with the 3.6.0rc and the warning disappeared (without any code changes). Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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