简体   繁体   English

Python 已装箱 arrays 的二维绘图

[英]Python 2D-plotting of already binned arrays

I have two really large arrays that can't fit in memory at once.我有两个非常大的 arrays 不能同时放入 memory。 I am interested in plotting a 2D histogram of these two arrays with a colorbar.我有兴趣用彩条绘制这两个 arrays 的二维直方图。 In my case I loop over subsequent chunks of arrays and keep appending first data to x and y , such that:在我的情况下,我遍历 arrays 的后续块并继续将第一个数据附加到xy ,这样:

n_bins=99
histogram = np.zeros(shape=(1,n_bins), dtype=np.float64)  
histogramy = np.zeros(shape=(1,n_bins), dtype=np.float64) 

and below happens in each ( for ) loop iteration when desired chunk length of x is reached:当达到所需的 x 块长度时,在每个 ( for ) 循环迭代中发生以下情况:

add_coip, _ = np.histogram(np.asarray(x)[:], bins=(xedges))
add_coipy, _ = np.histogram(np.asarray(y)[:], bins=(yedges))

histogramx += add_coip.astype(np.float64)
histogramy += add_coipy.astype(np.float64)
x,y=[],[] # reset lists to append next chunk

Though I get histogramx and histogramy binned properly, I am unable to plot a 2D histogram using these arrays.虽然我得到了histogramxhistogramy正确分箱,但我无法使用这些 arrays plot 二维直方图。 Note that histogramx and histogramy doesn not contain data, rather a binned-version of the data.请注意, histogramxhistogramy不包含数据,而是数据的分箱版本。 Any suggestions please?请问有什么建议吗?

PS: I understand using plt.bar as in this post but that's for a 1D plot! PS:我理解在这篇文章中使用plt.bar但那是一维图!

In case someone else comes across this, you can use plt.matshow as explained here , it has many of the options available that work for plt.hist2d .万一其他人遇到这种情况,您可以按照此处的说明使用plt.matshow ,它有许多适用于plt.hist2d的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM