Raise exception if negative height or width is passed to axes() #7783

Merged
merged 1 commit into from Jan 11, 2017

Conversation

Projects
None yet
5 participants
Contributor

samsontmr commented Jan 10, 2017

Fixes #7487

lib/matplotlib/axes/_base.py
@@ -483,6 +483,9 @@ def __init__(self, fig, rect,
self._position = rect
else:
self._position = mtransforms.Bbox.from_bounds(*rect)
+ x0, y0, x1, y1 = self._position.extents
+ if ((x1 - x0) < 0 or (y1 - y0) < 0):
@anntzer

anntzer Jan 10, 2017

Contributor

You can use self._position.width < 0 or self._position.height < 0.

@samsontmr

samsontmr Jan 11, 2017

Contributor

Thanks for the tip!

tacaswell added this to the 2.1 (next point release) milestone Jan 10, 2017

lib/matplotlib/axes/_base.py
@@ -483,6 +483,8 @@ def __init__(self, fig, rect,
self._position = rect
else:
self._position = mtransforms.Bbox.from_bounds(*rect)
+ if self._position.width < 0 or self._position.height < 0:
+ raise ValueError('Height and width specified must be non-negative')
@anntzer

anntzer Jan 11, 2017

Contributor

Very minor point: probably "Width and height must be non-negative" is better (as the order is x, y). I wouldn't add "specified" but I'll let a native speaker chime in :p

@samsontmr

samsontmr Jan 11, 2017

Contributor

I'm a native speaker ;p

@anntzer

anntzer Jan 11, 2017

Contributor

That's fine, the point about order still remains valid :p

@anntzer

anntzer Jan 11, 2017

Contributor

(I would suggest squashing the commits too.)

@samsontmr

samsontmr Jan 11, 2017

Contributor

Got it!

@samsontmr samsontmr Raise exception if width or height is negative
9926b05
Contributor

samsontmr commented Jan 11, 2017

Commits squashed!

codecov-io commented Jan 11, 2017 edited

Current coverage is 62.11% (diff: 50.00%)

Merging #7783 into master will decrease coverage by <.01%

@@             master      #7783   diff @@
==========================================
  Files           174        174          
  Lines         56028      56030     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          34805      34804     -1   
- Misses        21223      21226     +3   
  Partials          0          0          

Powered by Codecov. Last update d181f63...9926b05

Contributor

anntzer commented Jan 11, 2017

LGTM.

anntzer changed the title from Raise exception if negative height or width is passed to axes() to [MRG+1] Raise exception if negative height or width is passed to axes() Jan 11, 2017

@dopplershift

LGTM. Thanks for the contribution! 🎉

@dopplershift dopplershift merged commit d7b7522 into matplotlib:master Jan 11, 2017

3 of 5 checks passed

codecov/patch 50.00% of diff hit (target 62.12%)
Details
codecov/project 62.11% (-0.01%) compared to d181f63
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.004%) to 62.117%
Details

dopplershift changed the title from [MRG+1] Raise exception if negative height or width is passed to axes() to Raise exception if negative height or width is passed to axes() Jan 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment