Skip to content
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

CI: Fix matplolib release issues #48601

Merged
merged 9 commits into from Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/plotting/_core.py
Expand Up @@ -1017,7 +1017,7 @@ def __call__(self, *args, **kwargs):

>>> s = pd.Series([1, 3, 2])
>>> s.plot.line()
<AxesSubplot:ylabel='Density'>
<AxesSubplot: ylabel='Density'>

.. plot::
:context: close-figs
Expand Down
44 changes: 22 additions & 22 deletions pandas/plotting/_misc.py
Expand Up @@ -139,22 +139,22 @@ def scatter_matrix(

>>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
>>> pd.plotting.scatter_matrix(df, alpha=0.2)
array([[<AxesSubplot:xlabel='A', ylabel='A'>,
<AxesSubplot:xlabel='B', ylabel='A'>,
<AxesSubplot:xlabel='C', ylabel='A'>,
<AxesSubplot:xlabel='D', ylabel='A'>],
[<AxesSubplot:xlabel='A', ylabel='B'>,
<AxesSubplot:xlabel='B', ylabel='B'>,
<AxesSubplot:xlabel='C', ylabel='B'>,
<AxesSubplot:xlabel='D', ylabel='B'>],
[<AxesSubplot:xlabel='A', ylabel='C'>,
<AxesSubplot:xlabel='B', ylabel='C'>,
<AxesSubplot:xlabel='C', ylabel='C'>,
<AxesSubplot:xlabel='D', ylabel='C'>],
[<AxesSubplot:xlabel='A', ylabel='D'>,
<AxesSubplot:xlabel='B', ylabel='D'>,
<AxesSubplot:xlabel='C', ylabel='D'>,
<AxesSubplot:xlabel='D', ylabel='D'>]], dtype=object)
array([[<AxesSubplot: xlabel='A', ylabel='A'>,
<AxesSubplot: xlabel='B', ylabel='A'>,
<AxesSubplot: xlabel='C', ylabel='A'>,
<AxesSubplot: xlabel='D', ylabel='A'>],
[<AxesSubplot: xlabel='A', ylabel='B'>,
<AxesSubplot: xlabel='B', ylabel='B'>,
<AxesSubplot: xlabel='C', ylabel='B'>,
<AxesSubplot: xlabel='D', ylabel='B'>],
[<AxesSubplot: xlabel='A', ylabel='C'>,
<AxesSubplot: xlabel='B', ylabel='C'>,
<AxesSubplot: xlabel='C', ylabel='C'>,
<AxesSubplot: xlabel='D', ylabel='C'>],
[<AxesSubplot: xlabel='A', ylabel='D'>,
<AxesSubplot: xlabel='B', ylabel='D'>,
<AxesSubplot: xlabel='C', ylabel='D'>,
<AxesSubplot: xlabel='D', ylabel='D'>]], dtype=object)
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.scatter_matrix(
Expand Down Expand Up @@ -247,7 +247,7 @@ def radviz(
... }
... )
>>> pd.plotting.radviz(df, 'Category')
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
<AxesSubplot: xlabel='y(t)', ylabel='y(t + 1)'>
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.radviz(
Expand Down Expand Up @@ -315,7 +315,7 @@ def andrews_curves(
... 'pandas/main/pandas/tests/io/data/csv/iris.csv'
... )
>>> pd.plotting.andrews_curves(df, 'Name')
<AxesSubplot:title={'center':'width'}>
<AxesSubplot: title={'center': 'width'}>
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.andrews_curves(
Expand Down Expand Up @@ -449,7 +449,7 @@ def parallel_coordinates(
>>> pd.plotting.parallel_coordinates(
... df, 'Name', color=('#556270', '#4ECDC4', '#C7F464')
... )
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
<AxesSubplot: xlabel='y(t)', ylabel='y(t + 1)'>
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.parallel_coordinates(
Expand Down Expand Up @@ -500,15 +500,15 @@ def lag_plot(series: Series, lag: int = 1, ax: Axes | None = None, **kwds) -> Ax
>>> x = np.cumsum(np.random.normal(loc=1, scale=5, size=50))
>>> s = pd.Series(x)
>>> s.plot()
<AxesSubplot:xlabel='Midrange'>
<AxesSubplot: xlabel='Midrange'>

A lag plot with ``lag=1`` returns

.. plot::
:context: close-figs

>>> pd.plotting.lag_plot(s, lag=1)
<AxesSubplot:xlabel='y(t)', ylabel='y(t + 1)'>
<AxesSubplot: xlabel='y(t)', ylabel='y(t + 1)'>
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.lag_plot(series=series, lag=lag, ax=ax, **kwds)
Expand Down Expand Up @@ -543,7 +543,7 @@ def autocorrelation_plot(series: Series, ax: Axes | None = None, **kwargs) -> Ax
>>> spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
>>> s = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
>>> pd.plotting.autocorrelation_plot(s)
<AxesSubplot:title={'center':'width'}, xlabel='Lag', ylabel='Autocorrelation'>
<AxesSubplot: title={'center': 'width'}, xlabel='Lag', ylabel='Autocorrelation'>
"""
plot_backend = _get_plot_backend("matplotlib")
return plot_backend.autocorrelation_plot(series=series, ax=ax, **kwargs)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/plotting/common.py
Expand Up @@ -598,3 +598,16 @@ def _gen_two_subplots(f, fig, **kwargs):
else:
kwargs["ax"] = fig.add_subplot(212)
yield f(**kwargs)


try:
import matplotlib as mpl
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thx, changed


from pandas.util.version import Version

_mpl_version = mpl.__version__
_mpllv = Version(_mpl_version)
is_at_least_mpl_36 = _mpllv >= Version("3.6.0")

except ImportError:
is_at_least_mpl_36 = True
20 changes: 13 additions & 7 deletions pandas/tests/plotting/frame/test_frame.py
Expand Up @@ -27,6 +27,7 @@
from pandas.tests.plotting.common import (
TestPlotBase,
_check_plot_works,
is_at_least_mpl_36,
)

from pandas.io.formats.printing import pprint_thing
Expand All @@ -35,6 +36,7 @@

@td.skip_if_no_mpl
class TestDataFramePlots(TestPlotBase):
@pytest.mark.xfail(is_at_least_mpl_36, reason="Api changed")
@pytest.mark.slow
def test_plot(self):
df = tm.makeTimeDataFrame()
Expand Down Expand Up @@ -1534,17 +1536,17 @@ def test_errorbar_plot_iterator(self):

def test_errorbar_with_integer_column_names(self):
# test with integer column names
df = DataFrame(np.random.randn(10, 2))
df_err = DataFrame(np.random.randn(10, 2))
df = DataFrame(np.abs(np.random.randn(10, 2)))
df_err = DataFrame(np.abs(np.random.randn(10, 2)))
ax = _check_plot_works(df.plot, yerr=df_err)
self._check_has_errorbars(ax, xerr=0, yerr=2)
ax = _check_plot_works(df.plot, y=0, yerr=1)
self._check_has_errorbars(ax, xerr=0, yerr=1)

@pytest.mark.slow
def test_errorbar_with_partial_columns(self):
df = DataFrame(np.random.randn(10, 3))
df_err = DataFrame(np.random.randn(10, 2), columns=[0, 2])
df = DataFrame(np.abs(np.random.randn(10, 3)))
df_err = DataFrame(np.abs(np.random.randn(10, 2)), columns=[0, 2])
kinds = ["line", "bar"]
for kind in kinds:
ax = _check_plot_works(df.plot, yerr=df_err, kind=kind)
Expand Down Expand Up @@ -1632,9 +1634,11 @@ def test_table(self):
assert len(ax.tables) == 1

def test_errorbar_scatter(self):
df = DataFrame(np.random.randn(5, 2), index=range(5), columns=["x", "y"])
df = DataFrame(
np.abs(np.random.randn(5, 2)), index=range(5), columns=["x", "y"]
)
df_err = DataFrame(
np.random.randn(5, 2) / 5, index=range(5), columns=["x", "y"]
np.abs(np.random.randn(5, 2)) / 5, index=range(5), columns=["x", "y"]
)

ax = _check_plot_works(df.plot.scatter, x="x", y="y")
Expand All @@ -1661,7 +1665,9 @@ def _check_errorbar_color(containers, expected, has_err="has_xerr"):
)

# GH 8081
df = DataFrame(np.random.randn(10, 5), columns=["a", "b", "c", "d", "e"])
df = DataFrame(
np.abs(np.random.randn(10, 5)), columns=["a", "b", "c", "d", "e"]
)
ax = df.plot.scatter(x="a", y="b", xerr="d", yerr="e", c="red")
self._check_has_errorbars(ax, xerr=1, yerr=1)
_check_errorbar_color(ax.containers, "red", has_err="has_xerr")
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/plotting/test_datetimelike.py
Expand Up @@ -37,7 +37,10 @@
period_range,
)
from pandas.core.indexes.timedeltas import timedelta_range
from pandas.tests.plotting.common import TestPlotBase
from pandas.tests.plotting.common import (
TestPlotBase,
is_at_least_mpl_36,
)

from pandas.tseries.offsets import WeekOfMonth

Expand Down Expand Up @@ -260,6 +263,7 @@ def test_plot_multiple_inferred_freq(self):
ser = Series(np.random.randn(len(dr)), index=dr)
_check_plot_works(ser.plot)

@pytest.mark.xfail(is_at_least_mpl_36, reason="Api changed")
def test_uhf(self):
import pandas.plotting._matplotlib.converter as conv

Expand Down Expand Up @@ -1209,6 +1213,7 @@ def test_secondary_legend(self):
# TODO: color cycle problems
assert len(colors) == 4

@pytest.mark.xfail(is_at_least_mpl_36, reason="Api changed")
def test_format_date_axis(self):
rng = date_range("1/1/2012", periods=12, freq="M")
df = DataFrame(np.random.randn(len(rng), 3), rng)
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/plotting/test_hist_method.py
Expand Up @@ -16,6 +16,7 @@
from pandas.tests.plotting.common import (
TestPlotBase,
_check_plot_works,
is_at_least_mpl_36,
)


Expand Down Expand Up @@ -191,6 +192,7 @@ def test_hist_kwargs(self, ts):
ax = ts.plot.hist(align="left", stacked=True, ax=ax)
tm.close()

@pytest.mark.xfail(is_at_least_mpl_36, reason="Api changed")
@td.skip_if_no_scipy
def test_hist_kde(self, ts):

Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/plotting/test_series.py
Expand Up @@ -17,6 +17,7 @@
from pandas.tests.plotting.common import (
TestPlotBase,
_check_plot_works,
is_at_least_mpl_36,
)

import pandas.plotting as plotting
Expand Down Expand Up @@ -493,6 +494,7 @@ def test_kde_missing_vals(self):
# gh-14821: check if the values have any missing values
assert any(~np.isnan(axes.lines[0].get_xdata()))

@pytest.mark.xfail(is_at_least_mpl_36, reason="Api changed")
def test_boxplot_series(self, ts):
_, ax = self.plt.subplots()
ax = ts.plot.box(logy=True, ax=ax)
Expand Down Expand Up @@ -575,8 +577,10 @@ def test_errorbar_asymmetrical(self):
def test_errorbar_plot(self):

s = Series(np.arange(10), name="x")
s_err = np.random.randn(10)
d_err = DataFrame(np.random.randn(10, 2), index=s.index, columns=["x", "y"])
s_err = np.abs(np.random.randn(10))
d_err = DataFrame(
np.abs(np.random.randn(10, 2)), index=s.index, columns=["x", "y"]
)
# test line and bar plots
kinds = ["line", "bar"]
for kind in kinds:
Expand All @@ -597,8 +601,8 @@ def test_errorbar_plot(self):
# test time series plotting
ix = date_range("1/1/2000", "1/1/2001", freq="M")
ts = Series(np.arange(12), index=ix, name="x")
ts_err = Series(np.random.randn(12), index=ix)
td_err = DataFrame(np.random.randn(12, 2), index=ix, columns=["x", "y"])
ts_err = Series(np.abs(np.random.randn(12)), index=ix)
td_err = DataFrame(np.abs(np.random.randn(12, 2)), index=ix, columns=["x", "y"])

ax = _check_plot_works(ts.plot, yerr=ts_err)
self._check_has_errorbars(ax, xerr=0, yerr=1)
Expand Down