python直方图没有正确输出

时间:2017-07-30 13:49:43

标签: python histogram

以下代码用于在单个重叠图形中绘制所有信号并将脉冲高度(phs)存储在名为phs_array的数组中后,显示波形数据的直方图。它根本没有生成直方图,因为我只是这样:http://imgur.com/a/kWcvz

import csv                                
import numpy as np 
import matplotlib.pyplot as plt
import gzip
file1 = open(r'c:\Users\my_name\Documents\waveform_data\run11.dat')#,'rb')        
with gzip.open('run11.dat.gz', 'rb') as f:
    file_content = f.read()
data = csv.reader(file1, delimiter='\t') 

table = [row for row in data]  #"table" is the array that will be used for analysis
phs_array = [];    #Initiate an empty list, this will contain PHS values 

for i in range(len(table)/532):    
    plt.plot(table[(i*531+i):((i+1)*531+i)]);      #Plot of all pulses on single window
    phs_array.append(min(table[(i*531+i):((i+1)*531+i)])); #Fill phs_array with PH values 

phs_array = np.array(phs_array).astype(np.float);#convert all elements of PHS array into floats

plt.hist(phs_array, bins=500,range=(-0.61,-0.57),histtype='step'); #histogram of PHS

plt.title(r'Photoelectrons')
plt.xlabel('Time(ns)')
plt.ylabel('Voltage(v)')
plt.show()

0 个答案:

没有答案