Skip to content

Commit

Permalink
Fix(contour_array_cvfd): fix for masked value crash issue using trico…
Browse files Browse the repository at this point in the history
…ntour with matplotlib 3.1.1
  • Loading branch information
jlarsen-usgs committed Jul 11, 2019
1 parent 824ddb8 commit 7632fee
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions flopy/plot/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ def contour_array_cvfd(self, vertc, a, masked_values=None, **kwargs):
contour_set : matplotlib.pyplot.contour
"""
try:
import matplotlib.tri as tri
except ImportError:
err_msg = "Matplotlib must be updated to use contour_array"
raise ImportError(err_msg)

if 'ncpl' in kwargs:
nlay = self.layer + 1
ncpl = kwargs.pop('ncpl')
Expand All @@ -635,9 +641,14 @@ def contour_array_cvfd(self, vertc, a, masked_values=None, **kwargs):

plotarray = a[i0:i1]

ismasked = None
if masked_values is not None:
for mval in masked_values:
plotarray = np.ma.masked_equal(plotarray, mval)
if ismasked is None:
ismasked = np.equal(plotarray, mval)
else:
t = np.equal(plotarray, mval)
ismasked += t

if 'ax' in kwargs:
ax = kwargs.pop('ax')
Expand All @@ -648,8 +659,15 @@ def contour_array_cvfd(self, vertc, a, masked_values=None, **kwargs):
if 'cmap' in kwargs.keys():
kwargs.pop('cmap')

contour_set = ax.tricontour(vertc[:, 0], vertc[:, 1],
plotarray, **kwargs)
triang = tri.Triangulation(vertc[:, 0], vertc[:, 1])

if ismasked is not None:
ismasked = ismasked.flatten()
mask = np.any(np.where(ismasked[triang.triangles],
True, False), axis=1)
triang.set_mask(mask)

contour_set = ax.tricontour(triang, plotarray, **kwargs)

return contour_set

Expand Down Expand Up @@ -1395,17 +1413,17 @@ def __new__(cls, sr=None, ax=None, model=None, dis=None, layer=0,

modelgrid = None
if model is not None:
if (xul, yul, xll, yll, rotation) != (
None, None, None, None, None):
if (xul, yul, xll, yll, rotation) != (None, None,
None, None, None):
modelgrid = plotutil._set_coord_info(model.modelgrid,
xul, yul, xll, yll,
rotation)
elif sr is not None:
if length_multiplier is not None:
sr.length_multiplier = length_multiplier

if (xul, yul, xll, yll, rotation) != (
None, None, None, None, None):
if (xul, yul, xll, yll, rotation) != (None, None,
None, None, None):
sr.set_spatialreference(xul, yul, xll, yll, rotation)

if isinstance(sr, SpatialReferenceUnstructured):
Expand Down

0 comments on commit 7632fee

Please sign in to comment.