i have following code reads data csv file , creates 2d histogram: import numpy np import pandas pd import matplotlib mpl import matplotlib.pyplot plt #read in csv data filename = 'complete_storms_all_us_only.csv' df = pd.read_csv(filename) min_85 = df.min85 min_37 = df.min37 verification = df.one_min_15 #numbers x = min_85 y = min_37 h = verification #estimate 2d histogram nbins = 33 h, xedges, yedges = np.histogram2d(x,y,bins=nbins) #rotate , flip h h = np.rot90(h) h = np.flipud(h) #mask zeros hmasked = np.ma.masked_where(h==0,h) #calculate averages avgarr = np.zeros((nbins, nbins)) xbins = np.digitize(x, xedges[1:-1]) ybins = np.digitize(y, yedges[1:-1]) xb, yb, v in zip(xbins, ybins, verification): avgarr[yb, xb] += v divisor = h.copy() divisor[divisor==0.0] = np.nan avgarr /= divisor binavg = np.around((avgarr * 100), decimals=1) binper = np.ma.array(binavg, mask=np.isnan(binavg)) #plot 2d histogram using pcolor fig1 = plt.figure() plt.pcolormesh(xedges,yedg...
Comments
Post a Comment