Set mask for matplotlib tricontourf

I have a few numpy array containing data that I would visualize in a 2D grid. Some data is not physical, and I would like to mask this data. However, I could not figure out how to set the mask attribute correctly tricontour. I tried:

import matplotlib.pyplot as mp
import numpy as np

with open('some_data.dat', 'r') as infile:
        x, y, z = np.loadtxt(infile, usecols=(0, 1, 2), unpack=True)
isbad = np.less(z, 1.4) | np.greater(z, 2.1)
mp.tricontourf(x, y, z, mask = isbad)

But the result is simply not masked. I tried the masking part of the contour plot in matplotlib , i.e.

z2 = np.ma.array(z, mask= isbad)
mp.tricontourf(x, y, z2)

which didn't work either. I want to use tricontourfinstrad contourfbecause I do not want to group my data.

z[isbad] = np.nan

results in a Segmentation error when tricontourf is called

Here is the figure, the red colors are the ones that I would like to mark as non-physical. A colored contour plot with an overshooting color axis, due to unphysical data

+3
1

. ( z!), , , , ( (ntri, 3) ntri

triang = tr.Triangulation(x, y)
mask = np.all(np.where(isbad[triang.triangles], True, False), axis=1)
triang.set_mask(mask)
colplt = mp.tricontourf(triang, z)
mp.colorbar()

: http://matplotlib.org/examples/pylab_examples/tripcolor_demo.html

Colored contour plot with maksed unphysical region

+3

Source: https://habr.com/ru/post/1667102/


All Articles