Skip to content

Commit

Permalink
BUG : improved input clean up in Axes.{h|v}line
Browse files Browse the repository at this point in the history
 - passing in a (N, 1) shaped array as input causes the zipping to
   generate an extra dimension
 - use squeeze to get rid of useless dimensions
 - use atleast_1d to make sure scalars remain 1D ((1, ) vs () shape)
 - closes matplotlib#2197
  • Loading branch information
tacaswell committed Apr 27, 2014
1 parent 8fc41f8 commit 57494ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG
@@ -1,4 +1,7 @@
2014-04-22 Added an example showing the difference between
2014-04-27 Improved input clean up in Axes.{h|v}lines
Coerce input into a 1D ndarrays (after dealing with units).

2014-04-22 Added an example showing the difference between
interpolation = 'none' and interpolation = 'nearest' in
`imshow()` when saving vector graphics files.

Expand All @@ -7,7 +10,7 @@

2014-04-08 Fixed a bug in parasite_axes.py by making a list out
of a generator at line 263.

2014-02-25 In backend_qt4agg changed from using update -> repaint under
windows. See comment in source near `self._priv_update` for
longer explaination.
Expand Down
36 changes: 18 additions & 18 deletions lib/matplotlib/axes/_axes.py
Expand Up @@ -955,18 +955,16 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
if not iterable(xmax):
xmax = [xmax]

y = np.asarray(y)
xmin = np.asarray(xmin)
xmax = np.asarray(xmax)
y = np.atleast_1d(np.asarray(y).squeeze())
xmin = np.atleast_1d(np.asarray(xmin).squeeze())
xmax = np.atleast_1d(np.asarray(xmax).squeeze())

if len(xmin) == 1:
xmin = np.resize(xmin, y.shape)
if len(xmax) == 1:
xmax = np.resize(xmax, y.shape)
if y.ndim != 1:
raise ValueError("y must be scalar or 1D")

if len(xmin) != len(y):
if xmin.shape != y.shape:
raise ValueError('xmin and y are unequal sized sequences')
if len(xmax) != len(y):
if xmax.shape != y.shape:
raise ValueError('xmax and y are unequal sized sequences')

verts = [((thisxmin, thisy), (thisxmax, thisy))
Expand Down Expand Up @@ -1044,17 +1042,19 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
if not iterable(ymax):
ymax = [ymax]

x = np.asarray(x)
ymin = np.asarray(ymin)
ymax = np.asarray(ymax)
if len(ymin) == 1:
ymin = np.resize(ymin, x.shape)
if len(ymax) == 1:
ymax = np.resize(ymax, x.shape)
x = np.atleast_1d(np.asarray(x).squeeze())
ymin = np.atleast_1d(np.asarray(ymin).squeeze())
ymax = np.atleast_1d(np.asarray(ymax).squeeze())

if len(ymin) != len(x):
if x.ndim != 1:
print(x)
print(ymin)
print(ymax)
raise ValueError('x input must be scalar or 1 dimensional')

if ymin.shape != x.shape:
raise ValueError('ymin and x are unequal sized sequences')
if len(ymax) != len(x):
if ymax.shape != x.shape:
raise ValueError('ymax and x are unequal sized sequences')

Y = np.array([ymin, ymax]).T
Expand Down

0 comments on commit 57494ef

Please sign in to comment.