Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51595a1

Browse files
committed
Merge pull request matplotlib#2290 from selasley/master
Fix a recursion problem with masked arrays in get_converter
2 parents 2c46c0a + d3f79bf commit 51595a1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ def test_fill_between_interpolate():
584584

585585
# Test support for masked arrays.
586586
y2 = np.ma.masked_greater(y2, 1.0)
587+
# Test that plotting works for masked arrays with the first element masked
588+
y2[0] = np.ma.masked
587589
ax1 = fig.add_subplot(212, sharex=ax)
588590
ax1.plot(x, y1, x, y2, color='black')
589591
ax1.fill_between(x, y1, y2, where=y2>=y1, facecolor='green', interpolate=True)

lib/matplotlib/units.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,17 @@ def get_converter(self, x):
134134
converter = self.get(classx)
135135

136136
if isinstance(x, np.ndarray) and x.size:
137-
converter = self.get_converter(x.ravel()[0])
138-
return converter
137+
xravel = x.ravel()
138+
try:
139+
# pass the first value of x that is not masked back to get_converter
140+
if not np.all(xravel.mask):
141+
# some elements are not masked
142+
converter = self.get_converter(xravel[np.argmin(xravel.mask)])
143+
return converter
144+
except AttributeError:
145+
# not a masked_array
146+
converter = self.get_converter(xravel[0])
147+
return converter
139148

140149
if converter is None and iterable(x):
141150
for thisx in x:

0 commit comments

Comments
 (0)