I'm trying to create a polar histogram but not getting the expected result?

Viewed 36

I'm trying to create a polar histogram using python- matplotlib. My histogram bins are sorted in (x,y) coordinates but I'm trying to redistribute them radially in polar coordinates at evenly spaced (or non-evenly spaced) circles. I need ideas how to change the bins radially in terms of radius. Ideas are highly appreciated. Thank you!

import numpy as np
import matplotlib.pyplot as plt

E=np.ones((1,300000))
HITS=np.meshgrid([0,0,0,1],E)[0]
def Diffuser(HITS,ZOFFSET):  
    Diffused_X = []
    Diffused_Y = []
    Diffused_Z = []
    Etotal = 0

    for hit in HITS:
        electron_loc_x = hit[0]
        electron_loc_y = hit[1]
        electron_loc_z = hit[2]+ ZOFFSET   
        energy_deposit = hit[3] 
        Etotal += energy_deposit
        Nelectron = 1
        # Loop through the electrons 
        for electron in range(Nelectron):
            # calculate drift time for diffusion 
            T_drift = electron_loc_z / GasProps.Vd
            if (T_drift <=0):
                print("Warnign T_drift is negative")
                continue
            # electron lifetime
            if (np.random.uniform() >= np.exp(-T_drift/GasProps.Life_Time)):
                continue
            # diffuse the electrons position
            sigma_T = np.sqrt(2*GasProps.Dt*T_drift)
            sigma_L = np.sqrt(2*GasProps.Dl*T_drift)
            electron_x = np.random.normal(electron_loc_x,sigma_T)
            electron_y = np.random.normal(electron_loc_y,sigma_T)
            electron_z = np.random.normal(electron_loc_z,sigma_L)
            Diffused_X.append(electron_x)
            Diffused_Y.append(electron_y)
            Diffused_Z.append(electron_z)
    print("Evnet has {} eV and {} electrons made it!".format(round(Etotal,3), len(Diffused_Z)))           
    return Diffused_X, Diffused_Y, Diffused_Z
class Gas_Properties():
    def __init__(self):
        self.Wvalue = 5.3        # The work function of Gold in eV
        self.Vd = 196300         # cm/s
        self.Dt = 8184.632       # cm**2/s
        self.Dl = 1488.146       # cm**2/s
        self.Life_Time = 0.001   # in s
        
GasProps = Gas_Properties()
Diff_X, Diff_Y, Diff_Z = Diffuser(HITS, 10)
# Total Current Calculation
IT = 2.4        # Integration time 
t  = 1e6        # To convert from microsecond to second 
fA = 1e-15      # To convert from fAmps to Amps
muA = 1e6       # To convert from Amps to microAmps
# Setting up the histogram
plt.figure(figsize=(10,8))

binss = [np.arange(-10, 10, 0.1), np.arange(-10, 10, 0.1)]
cmap = plt.get_cmap('afmhot')
counts, xedges, yedges = np.histogram2d(Diff_X, Diff_Y, bins=binss)
x, y = np.meshgrid(binss[0], binss[1])
counts_Normed = counts * IT * t * fA  * muA /6242    # 6242 Electrons/fCoulomb
# plotting the histogram
h1 = plt.pcolormesh(x, y, np.ma.masked_where(counts == 0, counts_Normed).T, shading='auto', cmap=cmap)  # with mask
print(f" Expected total current of {counts_Normed.sum()} \u03bcA ")

plt.xlabel("X(cm)", fontsize=20)
plt.ylabel("Y(cm)", fontsize=20)
plt.xlim(-5,5)
plt.ylim(-5,5)

cb = plt.colorbar(h1)
cb.ax.tick_params(labelsize=18)
# cb.set_label('Electrons / Alpha',fontsize=20)
cb.set_label('Current [\u03bcA]',fontsize=20)
plt.tight_layout()
plt.title("Drift Distance, Z = 10 cm",fontsize=24)
plt.savefig("Ar-Current.png",dpi=250,bbox_inches='tight')
plt.show()

0 Answers
Related