Skip to content

Commit a6a09c1

Browse files
committed
Merge pull request #3014 from tacaswell/hline_vline_input_cleaning
BUG : improved input clean up in Axes.{h|v}line
2 parents 063e60f + 51b6bc9 commit a6a09c1

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

CHANGELOG

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
2014-04-22 Added an example showing the difference between
1+
2014-04-27 Improved input clean up in Axes.{h|v}lines
2+
Coerce input into a 1D ndarrays (after dealing with units).
3+
4+
2014-04-22 Added an example showing the difference between
25
interpolation = 'none' and interpolation = 'nearest' in
36
`imshow()` when saving vector graphics files.
47

@@ -7,7 +10,7 @@
710

811
2014-04-08 Fixed a bug in parasite_axes.py by making a list out
912
of a generator at line 263.
10-
13+
1114
2014-02-25 In backend_qt4agg changed from using update -> repaint under
1215
windows. See comment in source near `self._priv_update` for
1316
longer explaination.

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -955,19 +955,10 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
955955
if not iterable(xmax):
956956
xmax = [xmax]
957957

958-
y = np.asarray(y)
959-
xmin = np.asarray(xmin)
960-
xmax = np.asarray(xmax)
958+
y = np.ravel(y)
961959

962-
if len(xmin) == 1:
963-
xmin = np.resize(xmin, y.shape)
964-
if len(xmax) == 1:
965-
xmax = np.resize(xmax, y.shape)
966-
967-
if len(xmin) != len(y):
968-
raise ValueError('xmin and y are unequal sized sequences')
969-
if len(xmax) != len(y):
970-
raise ValueError('xmax and y are unequal sized sequences')
960+
xmin = np.resize(xmin, y.shape)
961+
xmax = np.resize(xmax, y.shape)
971962

972963
verts = [((thisxmin, thisy), (thisxmax, thisy))
973964
for thisxmin, thisxmax, thisy in zip(xmin, xmax, y)]
@@ -1044,23 +1035,12 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
10441035
if not iterable(ymax):
10451036
ymax = [ymax]
10461037

1047-
x = np.asarray(x)
1048-
ymin = np.asarray(ymin)
1049-
ymax = np.asarray(ymax)
1050-
if len(ymin) == 1:
1051-
ymin = np.resize(ymin, x.shape)
1052-
if len(ymax) == 1:
1053-
ymax = np.resize(ymax, x.shape)
1054-
1055-
if len(ymin) != len(x):
1056-
raise ValueError('ymin and x are unequal sized sequences')
1057-
if len(ymax) != len(x):
1058-
raise ValueError('ymax and x are unequal sized sequences')
1059-
1060-
Y = np.array([ymin, ymax]).T
1038+
x = np.ravel(x)
1039+
ymin = np.resize(ymin, x.shape)
1040+
ymax = np.resize(ymax, x.shape)
10611041

10621042
verts = [((thisx, thisymin), (thisx, thisymax))
1063-
for thisx, (thisymin, thisymax) in zip(x, Y)]
1043+
for thisx, thisymin, thisymax in zip(x, ymin, ymax)]
10641044
#print 'creating line collection'
10651045
coll = mcoll.LineCollection(verts, colors=colors,
10661046
linestyles=linestyles, label=label)

0 commit comments

Comments
 (0)