我刚刚开始使用Python进行编程,因为我需要开发一种可执行程序来执行直径分布。 我设法找到了可行的方法(下面的代码):
# Put here all modules you would need in order to represent your data
import matplotlib.pylab as plt
import numpy as np
import collections as c
from collections import Counter
from PIL import Image
import matplotlib.mlab as mlab
from scipy.optimize import curve_fit
import Tkinter as tk
from tkFileDialog import askopenfilename
# This prints the plot containing the diameter distribution of our sample
root = tk.Tk() ; root.withdraw()
filename = askopenfilename(parent=root)
f = open(filename)
with f as input: #Change the Results.txt file for your own .txt file
a = zip(*(line.strip().split('\t') for i,line in enumerate(input) if i != 0))
areas = a[1]
diam = []
for area in areas:
diam.append(round((np.sqrt(float(area)/ np.pi) * 2), 3)) # The number 3 tells us how many decimals will be shown
hist, bins = np.histogram(diam, 50)
diam.sort()
counts = c.Counter(diam)
'''This prints the table which includes all diameter values
and how many of them we can find on our sample# '''
table = sorted(counts.items())
col_labels = ['Diameter (nm)', 'Counts'] # In Diameter column you can add the units inside the empty parenthesis
table_vals = table
q = diam
mu = sum(q)/float(len(q))
variance = np.var(q)
sigma = np.sqrt(variance)
# In the plt.suptitle part --> change the d