Skip to content

COMPAT: matplotlib 3.4.0 #40718

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 8 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions pandas/plotting/_matplotlib/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ def inner():
mpl_ge_3_1_0 = _mpl_version("3.1.0", operator.ge)
mpl_ge_3_2_0 = _mpl_version("3.2.0", operator.ge)
mpl_ge_3_3_0 = _mpl_version("3.3.0", operator.ge)
mpl_ge_3_4_0 = _mpl_version("3.4.0", operator.ge)
7 changes: 6 additions & 1 deletion pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def handle_shared_axes(
row_num = lambda x: x.rowNum
col_num = lambda x: x.colNum

if compat.mpl_ge_3_4_0:
is_first_col = lambda x: x.get_subplotspec().is_first_col()
else:
is_first_col = lambda x: x.is_first_col()

if nrows > 1:
try:
# first find out the ax layout,
Expand Down Expand Up @@ -423,7 +428,7 @@ def handle_shared_axes(
# only the first column should get y labels -> set all other to
# off as we only have labels in the first column and we always
# have a subplot there, we can skip the layout test
if ax.is_first_col():
if is_first_col(ax):
continue
if sharey or _has_externally_shared_axis(ax, "y"):
_remove_labels_from_axis(ax.yaxis)
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,9 @@ def test_plot_scatter_with_categorical_data(self, x, y):

_check_plot_works(df.plot.scatter, x=x, y=y)

def test_plot_scatter_with_c(self):
def test_plot_scatter_with_c(self, request):
from pandas.plotting._matplotlib.compat import mpl_ge_3_4_0

df = DataFrame(
np.random.randn(6, 4),
index=list(string.ascii_letters[:6]),
Expand All @@ -760,6 +762,10 @@ def test_plot_scatter_with_c(self):

# n.b. there appears to be no public method
# to get the colorbar label
if mpl_ge_3_4_0:
mark = pytest.mark.xfail(reason="_label attribute removed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For recent versions, you can use ax.collections[0].colorbar.ax.get_ylabel() instead of the private attribute

request.node.add_marker(mark)

assert ax.collections[0].colorbar._label == "z"

cm = "cubehelix"
Expand Down