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

Skip to content

Commit 3b20ed1

Browse files
committed
Merge pull request #2290 from selasley/master
Fix a recursion problem with masked arrays in get_converter Conflicts: lib/matplotlib/units.py
1 parent 04b9ab9 commit 3b20ed1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/matplotlib/tests/test_axes.py

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

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

lib/matplotlib/units.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def default_units(x, axis):
4444
"""
4545
from __future__ import print_function
4646
from matplotlib.cbook import iterable, is_numlike
47+
import numpy as np
4748

4849

4950
class AxisInfo:
@@ -132,6 +133,21 @@ def get_converter(self, x):
132133
if classx is not None:
133134
converter = self.get(classx)
134135

136+
if isinstance(x, np.ndarray) and x.size:
137+
xravel = x.ravel()
138+
try:
139+
# pass the first value of x that is not masked back to
140+
# get_converter
141+
if not np.all(xravel.mask):
142+
# some elements are not masked
143+
converter = self.get_converter(
144+
xravel[np.argmin(xravel.mask)])
145+
return converter
146+
except AttributeError:
147+
# not a masked_array
148+
converter = self.get_converter(xravel[0])
149+
return converter
150+
135151
if converter is None and iterable(x):
136152
for thisx in x:
137153
# Make sure that recursing might actually lead to a solution,

0 commit comments

Comments
 (0)