import numpy as np; np.random.seed(17)
import matplotlib.pyplot as plt
# generate some random normal data
N = 100000
x = np.random.normal(-2, 3, N)
y = np.random.normal(3, 6, N)
# use np.where to set all y values less than -10 to -10
y = np.where(y < -10, -10, y)
# now apply histogram2d
xbins = np.linspace(-10, 10, 101)
ybins = np.linspace(-10, 10, 101)
H, xedges, yedges = np.histogram2d(y, x, bins=(xbins, ybins))
X, Y = np.meshgrid(xedges, yedges)
# plot data with pcolormesh
fig = plt.figure()
ax = fig.add_subplot(111)
img = ax.pcolormesh(X, Y, H)
ax.set_xlim(xedges.min(), xedges.max())
ax.set_ylim(yedges.min(), yedges.max())
plt.colorbar(img)
我能想到的最简单的方法就是在调用直方图之前过滤数据。下面是一个使用
np.where
过滤y数据的示例。你知道吗可以在y轴底部看到所有阈值的分布。你知道吗
相关问题 更多 >
编程相关推荐