Skip to content

TST: Address MPL 3.6 deprecation warnings #48695

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

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,10 @@ def _background_gradient(
rng = smax - smin
# extend lower / upper bounds, compresses color range
norm = mpl.colors.Normalize(smin - (rng * low), smax + (rng * high))
rgbas = plt.cm.get_cmap(cmap)(norm(gmap))
if cmap is None:
rgbas = mpl.colormaps[mpl.rcParams["image.cmap"]](norm(gmap))
else:
rgbas = mpl.colormaps[cmap](norm(gmap))

def relative_luminance(rgba) -> float:
"""
Expand Down Expand Up @@ -4210,7 +4213,7 @@ def css_calc(x, left: float, right: float, align: str, color: str | list | tuple
# use the matplotlib colormap input
with _mpl(Styler.bar) as (plt, mpl):
cmap = (
mpl.cm.get_cmap(cmap)
mpl.colormaps[cmap]
if isinstance(cmap, str)
else cmap # assumed to be a Colormap instance as documented
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/style/test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_background_gradient_gmap_wrong_series(styler_blank):
styler_blank.background_gradient(gmap=gmap, axis=None)._compute()


@pytest.mark.parametrize("cmap", ["PuBu", mpl.cm.get_cmap("PuBu")])
@pytest.mark.parametrize("cmap", ["PuBu", mpl.colormaps["PuBu"]])
def test_bar_colormap(cmap):
data = DataFrame([[1, 2], [3, 4]])
ctx = data.style.bar(cmap=cmap, axis=None)._compute().ctx
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,25 +479,29 @@ def is_grid_on():
mpl.rc("axes", grid=False)
obj.plot(kind=kind, **kws)
assert not is_grid_on()
self.plt.clf()

self.plt.subplot(1, 4 * len(kinds), spndx)
spndx += 1
mpl.rc("axes", grid=True)
obj.plot(kind=kind, grid=False, **kws)
assert not is_grid_on()
self.plt.clf()

if kind not in ["pie", "hexbin", "scatter"]:
self.plt.subplot(1, 4 * len(kinds), spndx)
spndx += 1
mpl.rc("axes", grid=True)
obj.plot(kind=kind, **kws)
assert is_grid_on()
self.plt.clf()

self.plt.subplot(1, 4 * len(kinds), spndx)
spndx += 1
mpl.rc("axes", grid=False)
obj.plot(kind=kind, grid=True, **kws)
assert is_grid_on()
self.plt.clf()

def _unpack_cycler(self, rcParams, field="color"):
"""
Expand Down