Except that the color should depend on the average z values for the (x, y) bin (rather than the number of entries in the (x, y) bin as in the default hexplot/2D histogram functionalities).推荐答案如果 binning 是您的要求,那么 binned_statistic_2d 可能适合您.举个例子:If binning is what you are asking, then binned_statistic_2d might work for you. Here's an example:from scipy.stats import binned_statistic_2dimport numpy as npx = np.random.uniform(0, 10, 1000)y = np.random.uniform(10, 20, 1000)z = np.exp(-(x-3)**2/5 - (y-18)**2/5) + np.random.random(1000)x_bins = np.linspace(0, 10, 10)y_bins = np.linspace(10, 20, 10)ret = binned_statistic_2d(x, y, z, statistic=np.mean, bins=[x_bins, y_bins])fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(12, 4))ax0.scatter(x, y, c=z)ax1.imshow(ret.statistic.T, origin='bottom', extent=(0, 10, 10, 20)) 这篇关于以直方图/hexplot的形式绘制2D箱中分散值的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 05:59