Skip to content

DEPS: Partial Matplotlib 3.7 support #51470

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
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 0 additions & 15 deletions pandas/plotting/_matplotlib/compat.py

This file was deleted.

8 changes: 6 additions & 2 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

import pandas.core.common as com
from pandas.core.frame import DataFrame
from pandas.util.version import Version

from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib import tools
Expand Down Expand Up @@ -784,8 +785,11 @@ def _make_legend(self) -> None:
if not self.subplots:
if leg is not None:
title = leg.get_title().get_text()
# Replace leg.LegendHandles because it misses marker info
handles = leg.legendHandles
# Replace leg.legend_handles because it misses marker info
if Version(mpl.__version__) < Version("3.7"):
handles = leg.legendHandles
else:
handles = leg.legend_handles
labels = [x.get_text() for x in leg.get_texts()]

if self.legend:
Expand Down
10 changes: 9 additions & 1 deletion pandas/tests/plotting/frame/test_frame_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TestPlotBase,
_check_plot_works,
)
from pandas.util.version import Version


@td.skip_if_no_mpl
Expand Down Expand Up @@ -639,11 +640,18 @@ def test_rcParams_bar_colors(self):
def test_colors_of_columns_with_same_name(self):
# ISSUE 11136 -> https://github.com/pandas-dev/pandas/issues/11136
# Creating a DataFrame with duplicate column labels and testing colors of them.
import matplotlib as mpl

df = DataFrame({"b": [0, 1, 0], "a": [1, 2, 3]})
df1 = DataFrame({"a": [2, 4, 6]})
df_concat = pd.concat([df, df1], axis=1)
result = df_concat.plot()
for legend, line in zip(result.get_legend().legendHandles, result.lines):
legend = result.get_legend()
if Version(mpl.__version__) < Version("3.7"):
handles = legend.legendHandles
else:
handles = legend.legend_handles
for legend, line in zip(handles, result.lines):
assert legend.get_color() == line.get_color()

def test_invalid_colormap(self):
Expand Down
15 changes: 13 additions & 2 deletions pandas/tests/plotting/frame/test_frame_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
date_range,
)
from pandas.tests.plotting.common import TestPlotBase
from pandas.util.version import Version


class TestFrameLegend(TestPlotBase):
Expand All @@ -19,6 +20,7 @@ class TestFrameLegend(TestPlotBase):
)
def test_mixed_yerr(self):
# https://github.com/pandas-dev/pandas/issues/39522
import matplotlib as mpl
from matplotlib.collections import LineCollection
from matplotlib.lines import Line2D

Expand All @@ -28,20 +30,29 @@ def test_mixed_yerr(self):
df.plot("x", "b", c="blue", yerr=None, ax=ax, label="blue")

legend = ax.get_legend()
result_handles = legend.legendHandles
if Version(mpl.__version__) < Version("3.7"):
result_handles = legend.legendHandles
else:
result_handles = legend.legend_handles

assert isinstance(result_handles[0], LineCollection)
assert isinstance(result_handles[1], Line2D)

def test_legend_false(self):
# https://github.com/pandas-dev/pandas/issues/40044
import matplotlib as mpl

df = DataFrame({"a": [1, 1], "b": [2, 3]})
df2 = DataFrame({"d": [2.5, 2.5]})

ax = df.plot(legend=True, color={"a": "blue", "b": "green"}, secondary_y="b")
df2.plot(legend=True, color={"d": "red"}, ax=ax)
legend = ax.get_legend()
result = [handle.get_color() for handle in legend.legendHandles]
if Version(mpl.__version__) < Version("3.7"):
handles = legend.legendHandles
else:
handles = legend.legend_handles
result = [handle.get_color() for handle in handles]
expected = ["blue", "green", "red"]
assert result == expected

Expand Down