我已经构建了一个直方图,反映了 matplotlib 中单元格的权重。从下面的直方图中可以看出,颜色区分非常模糊,人们几乎看不到它。 这可能是因为我选择了权衡点的方式。
如何提高直方图的“灵敏度”,以便它可以显示高权重区域和低权重区域之间的区别?
编辑
按要求附上的代码:
def generateFreqMap(trajectories, pointWeightLists, representatives):
# these three lists are all in a one-to-one correpondance
xOfAllPoints = [point[0] for trajectory in trajectories for point in trajectory]
yOfAllPoints = [point[1] for trajectory in trajectories for point in trajectory]
weightsOfAllPoints =[pointWeight for pointWeightList in pointWeightLists for pointWeight in pointWeightList]
leftBound, rightBound, topBound, bottomBound = min(xOfAllPoints), max(xOfAllPoints), max(yOfAllPoints), min(yOfAllPoints)
# parameters for histogram
x_edges = np.linspace(int(mt.floor(leftBound)), int(mt.ceil(rightBound)), int(mt.ceil(rightBound))-int(mt.floor(leftBound))+1)
y_edges = np.linspace(int(mt.floor(bottomBound)), int(mt.ceil(topBound)), int(mt.ceil(topBound))-int(mt.floor(bottomBound))+1)
# construct the histogram
wcounts = np.histogram2d(xOfAllPoints, yOfAllPoints, bins=(x_edges, y_edges), normed=False, weights=weightsOfAllPoints)[0]
# wcounts is a 2D array, with each element representing the weighted count in a bins
# show histogram
extent = x_edges[0], x_edges[-1], y_edges[0], y_edges[-1]
imshow(np.transpose(wcounts), extent=extent, alpha=0.5, cmap=cm.summer) # alpha controls the transparency
plt.xlabel('x (m)')
plt.ylabel('y (m)')
plt.title('Histogram of %i Trajectories'%TRAJECTORY_NUMBER);
savefig(PROJECT_PATH + '\\data\\%i_histogram.svg'%len(trajectories))
return wcounts
第 i 个点的权重为 0.995^i。所以第 1 点的权重最大,为 1。