【发布时间】:2015-03-10 13:03:04
【问题描述】:
我有一些 numpy 数组,其中包含我将在 2D 网格上可视化的数据。有些数据是非物理的,我想屏蔽这些数据。但是,我无法弄清楚如何正确设置tricontour 的掩码属性。我试过了:
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)
但生成的数字根本没有被掩盖。我试过masking part of a contourf plot in matplotlib,即
z2 = np.ma.array(z, mask= isbad)
mp.tricontourf(x, y, z2)
这也不起作用。我想使用contourf 的tricontourf instrad,因为我不想对我的数据进行网格化。
z[isbad] = np.nan
调用 tricontourf 时导致分段错误
这是图,红色是我想标记为非物理的。
【问题讨论】:
标签: python numpy matplotlib