Contexte: J'ai une image qui montre 3 CCD avec un tas d'interactions de rayons X montrés comme pixels brillants. J'ai tracé ces données sous la forme d'un histogramme (découper les données pour isoler chaque CCD individuel).Histogramme interactif utilisant matplotlib?
-je obtenir un histogramme qui ressemble à ceci:
Le grand pic à gauche est le bruit de fond (le pic réel de ce monte plus loin, mais je change la plage de l'axe pour montrer la autres parties de l'histogramme) et il devrait y avoir un pic beaucoup plus petit sur le côté droit (bien qu'il n'y en ait pas vraiment un visible sur cette image) qui sont les interactions aux rayons X.
Ma question spécifique .. Existe-t-il un moyen d'obtenir l'écart-type et la moyenne de chaque pic? Idéalement (et je ne suis pas sûr si c'est réellement possible en python) de dire, cliquez sur les deux côtés du pic et de calculer l'écart-type et la moyenne des données dans les deux clics?
J'utilise python 3.4 et version 1.4.3 matplotlib
Mon code est ci-dessous:
### read the data ###
a = np.fromfile(filename.img, dtype=np.uint32) #unpack the data and put it into a numpy array
image_data = np.reshape(a[3:], (-1,Cols))
### plotting the data ###
fig, ax = plt.subplots()
ax.imshow(image_data, cmap=cm.gray, interpolation='nearest', clim=(0,2000))
numrows, numcols = image_data.shape
def format_coord(x, y):
x = int(x +0.5)
y = int(y +0.5)
col = x
row = y
if col >= 0 and col < numcols and row >= 0 and row < numrows:
z = image_data[row, col]
return 'x=%1.0f, y=%1.0f, z=%1.0f' % (x, y, z)
else:
return 'x=%1.4f, y=%1.4f' % (x, y)
ax.format_coord = format_coord
plt.figure()
### Obtaining a histogram ###
which_CCD = int(input ('Which CCD? 1,2,3... '))
if which_CCD == 1:
CCD1_image = np.array(image_data[150:1500,300:1498])
CCD1_data=np.reshape(CCD1_image,np.product(CCD1_image.shape))
plt.hist(CCD1_data, bins = 2500, histtype='step')
plt.xlabel('Energy(ADC Channels)')
plt.title('CCD1 Histogram')
plt.figure()
elif which_CCD == 2:
CCD2_image = np.array(image_data[1800:3150,300:1498])
CCD2_data=np.reshape(CCD2_image,np.product(CCD2_image.shape))
plt.hist(CCD2_data, bins = 2500, histtype='step')
plt.xlabel('Energy(ADC Channels)')
plt.title('CCD2 Histogram', fontsize=12)
plt.figure()
elif which_CCD == 3:
CCD3_image = np.array(image_data[150:1500,1948:3146])
CCD3_data=np.reshape(CCD3_image,np.product(CCD3_image.shape))
plt.hist(CCD3_data, bins = 2500, histtype='step')
plt.xlabel('Energy(ADC Channels)')
plt.title('CCD3 Histogram')
plt.figure()
plt.show()
alors ce que vous voulez, c'est créer une interface graphique, qui montre cet histogramme, et vous pouvez sélectionner une plage de valeurs X, et il calculera la moyenne et STD des valeurs Y dans cette gamme? –