Skip to content

COMPAT: Matplotlib 3.5.0 #44523

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 7 commits into from
Nov 20, 2021
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 @@ -24,3 +24,4 @@ def inner():
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)
mpl_ge_3_5_0 = _mpl_version("3.5.0", operator.ge)
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ def get_locator(self, dmin, dmax):
locator = MilliSecondLocator(self.tz)
locator.set_axis(self.axis)

locator.set_view_interval(*self.axis.get_view_interval())
locator.set_data_interval(*self.axis.get_data_interval())
locator.axis.set_view_interval(*self.axis.get_view_interval())
locator.axis.set_data_interval(*self.axis.get_data_interval())
return locator

return dates.AutoDateLocator.get_locator(self, dmin, dmax)
Expand Down
1 change: 1 addition & 0 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ def _plot_colorbar(self, ax: Axes, **kwds):
# use the last one which contains the latest information
# about the ax
img = ax.collections[-1]
ax.grid(False)
Copy link
Member

Choose a reason for hiding this comment

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

what is this doing?

cbar = self.fig.colorbar(img, ax=ax, **kwds)

if mpl_ge_3_0_0():
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def setup_method(self, method):

from pandas.plotting._matplotlib import compat

self.compat = compat

mpl.rcdefaults()

self.start_date_to_int64 = 812419200000000000
Expand Down Expand Up @@ -569,6 +571,12 @@ def _unpack_cycler(self, rcParams, field="color"):
"""
return [v[field] for v in rcParams["axes.prop_cycle"]]

def get_x_axis(self, ax):
return ax._shared_axes["x"] if self.compat.mpl_ge_3_5_0() else ax._shared_x_axes

def get_y_axis(self, ax):
Copy link
Member

Choose a reason for hiding this comment

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

could annotate ax?

return ax._shared_axes["y"] if self.compat.mpl_ge_3_5_0() else ax._shared_y_axes


def _check_plot_works(f, filterwarnings="always", default_axes=False, **kwargs):
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ def test_area_sharey_dont_overwrite(self):
df.plot(ax=ax1, kind="area")
df.plot(ax=ax2, kind="area")

assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)
assert self.get_y_axis(ax1).joined(ax1, ax2)
assert self.get_y_axis(ax2).joined(ax1, ax2)

def test_bar_linewidth(self):
df = DataFrame(np.random.randn(5, 5))
Expand Down
32 changes: 16 additions & 16 deletions pandas/tests/plotting/frame/test_hist_box_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,33 @@ def test_axis_share_x_with_by(self):
ax1, ax2, ax3 = self.hist_df.plot.hist(column="A", by="C", sharex=True)

# share x
assert ax1._shared_x_axes.joined(ax1, ax2)
assert ax2._shared_x_axes.joined(ax1, ax2)
assert ax3._shared_x_axes.joined(ax1, ax3)
assert ax3._shared_x_axes.joined(ax2, ax3)
assert self.get_x_axis(ax1).joined(ax1, ax2)
assert self.get_x_axis(ax2).joined(ax1, ax2)
assert self.get_x_axis(ax3).joined(ax1, ax3)
assert self.get_x_axis(ax3).joined(ax2, ax3)

# don't share y
assert not ax1._shared_y_axes.joined(ax1, ax2)
assert not ax2._shared_y_axes.joined(ax1, ax2)
assert not ax3._shared_y_axes.joined(ax1, ax3)
assert not ax3._shared_y_axes.joined(ax2, ax3)
assert not self.get_y_axis(ax1).joined(ax1, ax2)
assert not self.get_y_axis(ax2).joined(ax1, ax2)
assert not self.get_y_axis(ax3).joined(ax1, ax3)
assert not self.get_y_axis(ax3).joined(ax2, ax3)

@pytest.mark.slow
def test_axis_share_y_with_by(self):
# GH 15079
ax1, ax2, ax3 = self.hist_df.plot.hist(column="A", by="C", sharey=True)

# share y
assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)
assert ax3._shared_y_axes.joined(ax1, ax3)
assert ax3._shared_y_axes.joined(ax2, ax3)
assert self.get_y_axis(ax1).joined(ax1, ax2)
assert self.get_y_axis(ax2).joined(ax1, ax2)
assert self.get_y_axis(ax3).joined(ax1, ax3)
assert self.get_y_axis(ax3).joined(ax2, ax3)

# don't share x
assert not ax1._shared_x_axes.joined(ax1, ax2)
assert not ax2._shared_x_axes.joined(ax1, ax2)
assert not ax3._shared_x_axes.joined(ax1, ax3)
assert not ax3._shared_x_axes.joined(ax2, ax3)
assert not self.get_x_axis(ax1).joined(ax1, ax2)
assert not self.get_x_axis(ax2).joined(ax1, ax2)
assert not self.get_x_axis(ax3).joined(ax1, ax3)
assert not self.get_x_axis(ax3).joined(ax2, ax3)

@pytest.mark.parametrize("figsize", [(12, 8), (20, 10)])
def test_figure_shape_hist_with_by(self, figsize):
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/plotting/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ def test__gen_two_subplots_with_ax(self):
next(gen)
axes = fig.get_axes()
assert len(axes) == 1
assert axes[0].get_geometry() == (2, 1, 2)
subplot_geometry = list(axes[0].get_subplotspec().get_geometry()[:-1])
subplot_geometry[-1] += 1
assert subplot_geometry == [2, 1, 2]
24 changes: 12 additions & 12 deletions pandas/tests/plotting/test_hist_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,35 +728,35 @@ def test_axis_share_x(self):
ax1, ax2 = df.hist(column="height", by=df.gender, sharex=True)

# share x
assert ax1._shared_x_axes.joined(ax1, ax2)
assert ax2._shared_x_axes.joined(ax1, ax2)
assert self.get_x_axis(ax1).joined(ax1, ax2)
assert self.get_x_axis(ax2).joined(ax1, ax2)

# don't share y
assert not ax1._shared_y_axes.joined(ax1, ax2)
assert not ax2._shared_y_axes.joined(ax1, ax2)
assert not self.get_y_axis(ax1).joined(ax1, ax2)
assert not self.get_y_axis(ax2).joined(ax1, ax2)

def test_axis_share_y(self):
df = self.hist_df
ax1, ax2 = df.hist(column="height", by=df.gender, sharey=True)

# share y
assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)
assert self.get_y_axis(ax1).joined(ax1, ax2)
assert self.get_y_axis(ax2).joined(ax1, ax2)

# don't share x
assert not ax1._shared_x_axes.joined(ax1, ax2)
assert not ax2._shared_x_axes.joined(ax1, ax2)
assert not self.get_x_axis(ax1).joined(ax1, ax2)
assert not self.get_x_axis(ax2).joined(ax1, ax2)

def test_axis_share_xy(self):
df = self.hist_df
ax1, ax2 = df.hist(column="height", by=df.gender, sharex=True, sharey=True)

# share both x and y
assert ax1._shared_x_axes.joined(ax1, ax2)
assert ax2._shared_x_axes.joined(ax1, ax2)
assert self.get_x_axis(ax1).joined(ax1, ax2)
assert self.get_x_axis(ax2).joined(ax1, ax2)

assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)
assert self.get_y_axis(ax1).joined(ax1, ax2)
assert self.get_y_axis(ax2).joined(ax1, ax2)

@pytest.mark.parametrize(
"histtype, expected",
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_area_sharey_dont_overwrite(self):
abs(self.ts).plot(ax=ax1, kind="area")
abs(self.ts).plot(ax=ax2, kind="area")

assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)
assert self.get_y_axis(ax1).joined(ax1, ax2)
assert self.get_y_axis(ax2).joined(ax1, ax2)

def test_label(self):
s = Series([1, 2])
Expand Down