Skip to content

BUG: scatter_matrix raising with 2d axis passed #38668

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
Dec 23, 2020
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 doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Period
Plotting
^^^^^^^^

- Bug in :func:`scatter_matrix` raising when 2d ``ax`` argument passed (:issue:`16253`)
-
-

Expand Down
7 changes: 4 additions & 3 deletions pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def create_subplots(
fig = plt.figure(**fig_kw)
else:
if is_list_like(ax):
ax = flatten_axes(ax)
if squeeze:
ax = flatten_axes(ax)
if layout is not None:
warnings.warn(
"When passing multiple axes, layout keyword is ignored", UserWarning
Expand All @@ -208,8 +209,8 @@ def create_subplots(
UserWarning,
stacklevel=4,
)
if len(ax) == naxes:
fig = ax[0].get_figure()
if ax.size == naxes:
fig = ax.flat[0].get_figure()
return fig, ax
else:
raise ValueError(
Expand Down
19 changes: 16 additions & 3 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ def test_bootstrap_plot(self):
@td.skip_if_no_mpl
class TestDataFramePlots(TestPlotBase):
@td.skip_if_no_scipy
def test_scatter_matrix_axis(self):
@pytest.mark.parametrize("pass_axis", [False, True])
def test_scatter_matrix_axis(self, pass_axis):
from pandas.plotting._matplotlib.compat import mpl_ge_3_0_0

scatter_matrix = plotting.scatter_matrix

ax = None
if pass_axis:
_, ax = self.plt.subplots(3, 3)

with tm.RNGContext(42):
df = DataFrame(np.random.randn(100, 3))

Expand All @@ -107,7 +112,11 @@ def test_scatter_matrix_axis(self):
UserWarning, raise_on_extra_warnings=mpl_ge_3_0_0()
):
axes = _check_plot_works(
scatter_matrix, filterwarnings="always", frame=df, range_padding=0.1
scatter_matrix,
filterwarnings="always",
frame=df,
range_padding=0.1,
ax=ax,
)
axes0_labels = axes[0][0].yaxis.get_majorticklabels()

Expand All @@ -121,7 +130,11 @@ def test_scatter_matrix_axis(self):
# we are plotting multiples on a sub-plot
with tm.assert_produces_warning(UserWarning):
axes = _check_plot_works(
scatter_matrix, filterwarnings="always", frame=df, range_padding=0.1
scatter_matrix,
filterwarnings="always",
frame=df,
range_padding=0.1,
ax=ax,
)
axes0_labels = axes[0][0].yaxis.get_majorticklabels()
expected = ["-1.0", "-0.5", "0.0"]
Expand Down