Skip to content

Commit

Permalink
COMPAT: Matplotlib 3.5.0 (pandas-dev#44523)
Browse files Browse the repository at this point in the history
* COMPAT: Matplotlib 3.5.0

* try another way

* typo

* one more typo

* Update test_common.py

* Update converter.py

* fix deprecation warnings?
  • Loading branch information
lithomas1 authored Nov 20, 2021
1 parent 59d031f commit 8b2477d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
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)
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):
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

0 comments on commit 8b2477d

Please sign in to comment.