Skip to content

Backport PR #40718 on branch 1.2.x (COMPAT: matplotlib 3.4.0) #40739

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
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
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 @@ -366,6 +366,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 @@ -397,7 +402,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
11 changes: 7 additions & 4 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,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 @@ -709,9 +711,10 @@ def test_plot_scatter_with_c(self):
# default to Greys
assert ax.collections[0].cmap.name == "Greys"

# n.b. there appears to be no public method
# to get the colorbar label
assert ax.collections[0].colorbar._label == "z"
if mpl_ge_3_4_0():
assert ax.collections[0].colorbar.ax.get_ylabel() == "z"
else:
assert ax.collections[0].colorbar._label == "z"

cm = "cubehelix"
ax = df.plot.scatter(x="x", y="y", c="z", colormap=cm)
Expand Down