Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix traceback for vlines/hlines, when an empty list or array passed in for x/y. #1000

Merged
merged 3 commits into from

2 participants

@dhyams

Handle the edge case in matplotlib.axes.vlines and matplotlib.axes.hlines where an empty list or array is passed in as x (or y). Previously, the vlines/hlines routines would raise an exception when min() was called, if x (or y) was an empty list.

@dhyams dhyams Handle the edge case in matplotlib.axes.vlines, where an empty list o…
…r 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
8f50a76
@WeatherGod
Collaborator

I presume the same should be done for hlines() as well?

@WeatherGod
Collaborator

Congrats on getting the 1000th issue, btw.

@dhyams

Re: for hlines...yes...I presume so. I forgot that matplotlib supported hlines :/

I'll check it and perform the same change there for this pull request.

@dhyams

Fix added for hlines as well.

@WeatherGod
Collaborator

Thanks for that. My only other concern is what happens if the length of the input array is one. I am pretty sure update_datalim() is smart about this, but I can't remember off the top of my head.

@dhyams

Re: 1000th issue: Is there a door prize? ;)

@dhyams

Re: update_datalim(): Just in the last few days, I have had a plot or two that had a single point with error bars. The autoscaling seemed to work fine, so I think update_datalim() is OK with just one point.

@WeatherGod
Collaborator

Re: door prize: Yeah, you get a free PR merge. Congrats!

@WeatherGod WeatherGod merged commit f6b7f28 into matplotlib:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 10, 2012
  1. @dhyams

    Handle the edge case in matplotlib.axes.vlines, where an empty list o…

    dhyams authored
    …r 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
  2. @dhyams

    Handled edge case for hlines also; if y is an empty list or zero-leng…

    dhyams authored
    …th array, the routine
    
    would raise an exception.
  3. @dhyams

    oops; failed to commit after fixing this little bugaboo; should have …

    dhyams authored
    …been len(y) instead of len(x)
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 15 deletions.
  1. +17 −15 lib/matplotlib/axes.py
View
32 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(y) > 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
@@ -3706,16 +3707,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
Something went wrong with that request. Please try again.