John M
John M

Reputation: 273

Fixed histogram2d bin vectors

I'm trying to run something in a for loop and analyze a 2D histogram of some data where the bin vectors do not change. They have to be fixed. So far I have

import numpy as np
nbins = 300
XgBins=np.linspace(3.21,3.31, nbins)
volBins=np.linspace(0,0.00032,nbins)

for k in range(0,121):    
    data = np.genfromtxt('/home/file'+str(k)+'.csv',delimiter=',', dtype = float)
    Xg = [row[8] for row in data]
    vol = [row[14] for row in data] 

    Hbg, xedgesbg, yedgesbg = np.histogram2d(Xg[1:len(Xg)],vol[1:len(vol)], range = [XgBins, volBins])

But, I'm getting a

ValueError: too many values to unpack

error. I'm not quite sure it's doing what I want it to do. What am I missing here?

Upvotes: 0

Views: 50

Answers (1)

user545424
user545424

Reputation: 16179

The docs show that if you want to explicitly provide bins, they should be provided with the bins keyword argument, i.e.

H, x, y = np.histogram2d(Xg[1:len(Xg)],vol[1:len(vol)], bins=[XgBins, volBins])

Upvotes: 2

Related Questions