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

Skip to content

[Bug]: Some styles trigger pcolormesh grid deprecation #21723

@prisae

Description

@prisae

Bug summary

Calling plot_surface followed by fig.colorbar results in the following deprecation warning:

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.

However, setting ax.grid(False) first does not help, the Warning is still shown.

Code for reproduction

Edit: As noted further down in the discussion: The warning does not appear for the default style. But if you load, e.g., plt.style.use('bmh'), you will see the warning.

# https://matplotlib.org/stable/gallery/mplot3d/surface3d.html

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import numpy as np

plt.style.use('bmh')  # Edit: One of the styles with which you will see the warning

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)

# Customize the z axis.
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
# A StrMethodFormatter is used automatically
ax.zaxis.set_major_formatter('{x:.02f}')

# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

Actual outcome

 MatplotlibDeprecationWarning: 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.
 fig.colorbar(surf, shrink=0.5, aspect=5)

Expected outcome

No Warning or a warning with a fix that works.

Additional information

Works fine for matplotlib<3.5.

Operating system

Linux

Matplotlib Version

3.5.0

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

3.88

Jupyter version

6.4.0

Installation

conda

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions