【发布时间】:2018-11-18 06:52:45
【问题描述】:
在查看this answer 之后,我已经知道如何设置一维直方图的 bin 大小,但我不知道如何为二维直方图执行此操作。我已经参考了二维直方图的 Numpy 和 Matplotlib 页面,但是我所有调整 bin 大小的尝试都不起作用/运行。我希望我的 bin 的长度为 20,宽度为 2。
示例代码:
import numpy as np
import matplotlib.pyplot as plt
import math
dataX = np.random.uniform(-50,50,100)
dataY = np.random.uniform(-50,50,100)
binWidth = 2.0
binLength = 20.0
xMin = min(dataX)
xMax = max(dataX)
yMin = min(dataY)
yMax = max(dataY)
#this and all other similar attempts that I have tried did not run
np.histogram2d(dataX, dataY, bins = np.arange((xMin,xMax + binWidth),(yMin,yMin +binLength),(binWidth,binLength)))
期待您的提示/帮助/建议。
【问题讨论】:
-
您对
np.arange的使用是错误的。对于hist2d,您可以提供数组而不是元组:bins = [x,y]
标签: python numpy matplotlib