Make histogram from data in python -
i trying make histogram data saved in .dat file: have made other types of plots, when trying make histogram receive error: valueerror: x has 1 data point. bins or range kwarg must given. table has (many) more 1 data point! code below...
import numpy np import matplotlib.pyplot plt a=open('/24_5_15b.dat','r') header0=a.readline() w1=[] w2=[] line in a: line=line.strip() columns=line.split() w1=float(columns[13]) w2=float(columns[15]) w1=np.asarray(w1) w2=np.asarray(w2) n, bins, patches = plt.hist(w1, 20, normed=1, histtype='bar', rwidth=0.8) plt.show()
when ask print w1 prints values. numbers floats - make difference? thanks...
from looks of this, trying plot histogram first line:
for line in a: ... n, bins, patches = plt.hist(w1, 20, normed=1, histtype='bar', rwidth=0.8)
to make histogram, need pass of data, not 1 @ time.
i recommend using genfromtxt
too, can use like:
a = np.genfromtxt('/24_5_15b.dat') # delimiter " " default w1 = a[:,13] w2 = a[:,15] plt.hist(w1, ...)
Comments
Post a Comment