From efe7d7a29e558f07f6d67044afa75942b400b940 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 15 Jul 2018 10:04:11 -0700 Subject: [PATCH 1/3] FIX: let boxplot take pandas position --- lib/matplotlib/axes/_axes.py | 6 +++--- lib/matplotlib/axis.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 4266cba8697b..75dfc23f2d37 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3901,10 +3901,10 @@ def dopatch(xs, ys, **kwargs): N = len(bxpstats) datashape_message = ("List of boxplot statistics and `{0}` " "values must have same the length") - # check position if positions is None: positions = list(range(1, N + 1)) - elif len(positions) != N: + positions = self.convert_xunits(positions) + if len(positions) != N: raise ValueError(datashape_message.format("positions")) # width @@ -6048,7 +6048,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None, # convert to one dimensional arrays C = C.ravel() - coords = np.column_stack((X, Y)).astype(float, copy=False) + coords = np.column_stack((X, Y)).astype(float) collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords, antialiased=antialiased, shading=shading, **kwargs) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 31ec36f8e86e..f8cbcb3f5ab9 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -4,6 +4,8 @@ import datetime import logging +import numbers +import warnings import numpy as np @@ -1477,9 +1479,14 @@ def have_units(self): return self.converter is not None or self.units is not None def convert_units(self, x): - # If x is already a number, doesn't need converting + # If x is already a number, doesn't need converting, but + # some iterables need to be massaged a bit... if munits.ConversionInterface.is_numlike(x): - return x + if isinstance(x, list) or isinstance(x, numbers.Number): + return x + if issubclass(type(x), np.ma.MaskedArray): + return np.ma.asarray(x) + return np.asarray(x) if self.converter is None: self.converter = munits.registry.get_converter(x) From 4640237adc65200562d5548757949dfe6725f522 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sun, 15 Jul 2018 11:21:44 -0700 Subject: [PATCH 2/3] TST: add smoketest --- lib/matplotlib/tests/test_dates.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 35e005346335..904055838b04 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -616,6 +616,16 @@ def tz_convert(*args): _test_date2num_dst(pd.date_range, tz_convert) +def test_dateboxplot_pandas(pd): + # smoke test that this doesn't fail. + data = np.random.rand(5,2) + years = pd.date_range('1/1/2000', + periods=2, freq=pd.DateOffset(years=1)).year + # Does not work + plt.figure() + plt.boxplot(data, positions=years) + + def _test_rrulewrapper(attach_tz, get_tz): SYD = get_tz('Australia/Sydney') From b16c311f5ed81478e74e8f5bac5608bdfd98f57f Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 16 Jul 2018 05:46:24 -0700 Subject: [PATCH 3/3] Fix datetime mess --- lib/matplotlib/dates.py | 5 +++++ lib/matplotlib/testing/conftest.py | 17 ++++------------- lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ lib/matplotlib/tests/test_dates.py | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 339114fbb281..6607dae18279 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -419,6 +419,11 @@ def date2num(d): return _dt64_to_ordinalf(d) if not d.size: return d + if hasattr(d, 'dtype'): + if ((isinstance(d, np.ndarray) and + np.issubdtype(d.dtype, np.datetime64)) or + isinstance(d, np.datetime64)): + return _dt64_to_ordinalf(d) return _to_ordinalf_np_vectorized(d) diff --git a/lib/matplotlib/testing/conftest.py b/lib/matplotlib/testing/conftest.py index 8cb90e083648..b2bf07204d75 100644 --- a/lib/matplotlib/testing/conftest.py +++ b/lib/matplotlib/testing/conftest.py @@ -91,17 +91,8 @@ def pd(): pd = pytest.importorskip('pandas') try: from pandas.plotting import ( - register_matplotlib_converters as register) + deregister_matplotlib_converters as deregister) + deregister() except ImportError: - from pandas.tseries.converter import register - register() - try: - yield pd - finally: - try: - from pandas.plotting import ( - deregister_matplotlib_converters as deregister) - except ImportError: - pass - else: - deregister() + pass + return pd diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 03f2a6de0bc1..dbeef3ef23d5 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5422,6 +5422,18 @@ def test_pandas_bar_align_center(pd): fig.canvas.draw() +def test_pandas_data_unpack(pd): + # smoke test for all these different calling methods. + dates = [datetime.datetime(2018, 7, i) for i in range(1, 5)] + values = np.cumsum(np.random.rand(len(dates))) + df = pd.DataFrame({"dates": dates, "values": values}) + plt.plot(df["dates"].values, df["values"]) + plt.scatter(df["dates"], df["values"]) + plt.plot("dates", "values", data=df) + plt.scatter(x="dates", y="values", data=df) + plt.draw() + + def test_axis_set_tick_params_labelsize_labelcolor(): # Tests fix for issue 4346 axis_1 = plt.subplot() diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 904055838b04..6606ba95210a 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -618,7 +618,7 @@ def tz_convert(*args): def test_dateboxplot_pandas(pd): # smoke test that this doesn't fail. - data = np.random.rand(5,2) + data = np.random.rand(5, 2) years = pd.date_range('1/1/2000', periods=2, freq=pd.DateOffset(years=1)).year # Does not work pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy