关于我在数组中屏蔽零值的方式,在执行his2d时会导致错误。我试试:
x = ma.masked_array([0.17478785046728973, 0.21854713940370668, 0.7354304690743048,
1.1052309124767226, 0.3450562200956937, 0])
x[5] = ma.masked_all(1)
y = ma.masked_array([0.17478785046728973, 0.21854713940370668, 0.7354304690743048,
1.1052309124767226, 0.3450562200956937, 0])
plt.hist2d(x, y, bins = 10)
plt.show()
我认为它不喜欢与小数有关,因为这是错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-82-38bb844ac43e> in <module>()
9 1.1052309124767226, 0.3450562200956937, 0])
10
---> 11 plt.hist2d(c, d, bins = 10)
12 plt.show()
/Users/eebp/anaconda/envs/Python2/lib/python2.7/site-packages/matplotlib/pyplot.pyc in hist2d(x, y, bins, range, normed, weights, cmin, cmax, hold, data, **kwargs)
2983 ret = ax.hist2d(x, y, bins=bins, range=range, normed=normed,
2984 weights=weights, cmin=cmin, cmax=cmax, data=data,
-> 2985 **kwargs)
2986 finally:
2987 ax.hold(washold)
/Users/eebp/anaconda/envs/Python2/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/Users/eebp/anaconda/envs/Python2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in hist2d(self, x, y, bins, range, normed, weights, cmin, cmax, **kwargs)
6300 range = __builtins__["range"]
6301 h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=bin_range,
-> 6302 normed=normed, weights=weights)
6303
6304 if cmin is not None:
/Users/eebp/anaconda/envs/Python2/lib/python2.7/site-packages/numpy/lib/twodim_base.pyc in histogram2d(x, y, bins, range, normed, weights)
712 xedges = yedges = asarray(bins, float)
713 bins = [xedges, yedges]
--> 714 hist, edges = histogramdd([x, y], bins, range, normed, weights)
715 return hist, edges[0], edges[1]
716
/Users/eebp/anaconda/envs/Python2/lib/python2.7/site-packages/numpy/lib/function_base.pyc in histogramdd(sample, bins, range, normed, weights)
800 mindiff = dedges[i].min()
801 if not np.isinf(mindiff):
--> 802 decimal = int(-log10(mindiff)) + 6
803 # Find which points are on the rightmost edge.
804 not_smaller_than_edge = (sample[:, i] >= edges[i][-1])
ValueError: cannot convert float NaN to integer
如果我绘制的数组没有我自己的掩码值:plt.hist2d(y, y, bins = 10)
那么就可以了。我用错误的方法来掩饰吗?我最初使用该语法来掩盖3D数组的2D切片,所以我想知道我是否在不必要地在数组中创建数组。