From f255c33f9f4a708a1462cf8e817bf5468acab77b Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 1 Dec 2015 18:34:44 -0500 Subject: [PATCH 1/3] Fix #5572: Allow passing empty range to broken_barh --- lib/matplotlib/axes/_axes.py | 12 ++++++++++-- lib/matplotlib/tests/test_axes.py | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 61d1eef82cb9..5313e8543942 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2339,8 +2339,16 @@ def broken_barh(self, xranges, yrange, **kwargs): .. plot:: mpl_examples/pylab_examples/broken_barh.py """ # process the unit information - self._process_unit_info(xdata=xranges[0], - ydata=yrange[0], + if len(xranges): + xdata = xranges[0] + else: + xdata = None + if len(yrange): + ydata = yrange[0] + else: + ydata = None + self._process_unit_info(xdata=xdata, + ydata=ydata, kwargs=kwargs) xranges = self.convert_xunits(xranges) yrange = self.convert_yunits(yrange) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 5c30e56cb5ed..20c5c0a5439f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4241,6 +4241,12 @@ def _helper_y(ax): assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim) +@cleanup +def test_broken_barh_empty(): + fig, ax = plt.subplots() + ax.broken_barh([], (.1, .5)) + + if __name__ == '__main__': import nose import sys From 76d681b9d26fbb4499730f8c64e9bc055eddaafb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 2 Dec 2015 15:36:07 -0500 Subject: [PATCH 2/3] Use iterator rather than index --- lib/matplotlib/axes/_axes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 5313e8543942..e9a15fbe0296 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2340,11 +2340,11 @@ def broken_barh(self, xranges, yrange, **kwargs): """ # process the unit information if len(xranges): - xdata = xranges[0] + xdata = six.next(iter(xranges)) else: xdata = None if len(yrange): - ydata = yrange[0] + ydata = six.next(iter(yranges)) else: ydata = None self._process_unit_info(xdata=xdata, From 115fca7ede6ec440f782d2b0221b732b91abd079 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 22 Dec 2015 13:32:33 -0500 Subject: [PATCH 3/3] Fix typo --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e9a15fbe0296..59f922b16128 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2344,7 +2344,7 @@ def broken_barh(self, xranges, yrange, **kwargs): else: xdata = None if len(yrange): - ydata = six.next(iter(yranges)) + ydata = six.next(iter(yrange)) else: ydata = None self._process_unit_info(xdata=xdata,