From 8f50a76d6c24ed402ce21f42b31beea6c97f88f7 Mon Sep 17 00:00:00 2001 From: Daniel Hyams Date: Tue, 10 Jul 2012 08:01:04 -0400 Subject: [PATCH 1/3] Handle the edge case in matplotlib.axes.vlines, where an empty list or array is passed in as x. Previously, the vlines routine would raise an exception when min(x) was called, if x was an empty list.wq --- lib/matplotlib/axes.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index db2319383ed7..8f3aa895a223 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3706,16 +3706,17 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', linestyles=linestyles, label=label) self.add_collection(coll) coll.update(kwargs) + + if len(x) > 0: + minx = min( x ) + maxx = max( x ) - minx = min( x ) - maxx = max( x ) + miny = min( min(ymin), min(ymax) ) + maxy = max( max(ymin), max(ymax) ) - miny = min( min(ymin), min(ymax) ) - maxy = max( max(ymin), max(ymax) ) - - corners = (minx, miny), (maxx, maxy) - self.update_datalim(corners) - self.autoscale_view() + corners = (minx, miny), (maxx, maxy) + self.update_datalim(corners) + self.autoscale_view() return coll From 554bd483cad7728655c830607bba65929dd052af Mon Sep 17 00:00:00 2001 From: Daniel Hyams Date: Tue, 10 Jul 2012 09:37:00 -0400 Subject: [PATCH 2/3] Handled edge case for hlines also; if y is an empty list or zero-length array, the routine would raise an exception. --- lib/matplotlib/axes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 8f3aa895a223..b64aafb27739 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3626,15 +3626,16 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', self.add_collection(coll) coll.update(kwargs) - minx = min(xmin.min(), xmax.min()) - maxx = max(xmin.max(), xmax.max()) - miny = y.min() - maxy = y.max() + if len(x) > 0: + minx = min(xmin.min(), xmax.min()) + maxx = max(xmin.max(), xmax.max()) + miny = y.min() + maxy = y.max() - corners = (minx, miny), (maxx, maxy) + corners = (minx, miny), (maxx, maxy) - self.update_datalim(corners) - self.autoscale_view() + self.update_datalim(corners) + self.autoscale_view() return coll From d65269db2bce724a9853b763264ca4ef8980b38d Mon Sep 17 00:00:00 2001 From: Daniel Hyams Date: Tue, 10 Jul 2012 09:39:39 -0400 Subject: [PATCH 3/3] oops; failed to commit after fixing this little bugaboo; should have been len(y) instead of len(x) --- lib/matplotlib/axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index b64aafb27739..e4c622158b09 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3626,7 +3626,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', self.add_collection(coll) coll.update(kwargs) - if len(x) > 0: + if len(y) > 0: minx = min(xmin.min(), xmax.min()) maxx = max(xmin.max(), xmax.max()) miny = y.min()