Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mroeschke opened this issue Aug 14, 2022 · 4 comments
Closed

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

mroeschke opened this issue Aug 14, 2022 · 4 comments

Comments

@mroeschke
Copy link

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

@timhoffm
Copy link
Member

timhoffm commented Aug 14, 2022

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.

@oscargus
Copy link
Contributor

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.

@oscargus
Copy link
Contributor

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

@mroeschke
Copy link
Author

mroeschke commented Aug 30, 2022

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
Projects
None yet
Development

No branches or pull requests

3 participants