样例:

self.distChangeRateStrLeft = tk.StringVar(value='1,0')
# state=tk.DISABLED 默认禁止输入
self.distChangeRateEntryLeft = ttk.Entry(topFrame2, width=8, textvariable=self.distChangeRateStrLeft, state=tk.DISABLED)
self.distChangeRateEntryLeft.pack(side=tk.LEFT, padx=4)

盆栽时可用腐叶土3份和砂土1份混合作基质。

平时浇水要待干透再浇,不必担心会干死,施肥不必过勤,否则造成旺长,并有可能造成植株腐烂,生长季每月施1-2次肥即可。

摘心

小苗的摘心,要注意防止伤害茎杆,截取一小段株心就可以了。截取之后,给切口缚上保护膜或者是塑料袋都行,防风防腐。
成株落地生根的修剪,最好的截取位置是植株三分之二处。既不损害植株接下来的生长,又能保持株型的优美。

拟合直线

model = np.polyfit(df_flat['code'], df_flat['data'], 1)
predict = np.poly1d(model)
x_lin_reg = range(df_flat.at[0, 'code'] - 800, df_flat.at[len(df_flat) - 1, 'code'] + 800)
y_lin_reg = predict(x_lin_reg)
plt.plot(x_lin_reg, y_lin_reg, c='r')
阅读全文 »

# tkinter 里面调用的方式
def draw_circle(self, df_calc, ax1, pt):
x = df_calc['x']
y = df_calc['y']

# coordinates of the barycenter
x_m = np.mean(x)
y_m = np.mean(y)

method_2 = "leastsq"

def calc_R(c):
""" calculate the distance of each 2D points from the center c=(xc, yc) """
return np.sqrt((x - c[0]) ** 2 + (y - c[1]) ** 2)

def calc_ecart(c):
""" calculate the algebraic distance between the 2D points and the mean circle centered at c=(xc, yc) """
Ri = calc_R(c)
return Ri - Ri.mean()

center_estimate = x_m, y_m
try:
center_2, ier = optimize.leastsq(calc_ecart, center_estimate)
except Exception as e:
import traceback
traceback.print_exc()
errMsg = traceback.format_exc()
self.status.config(fg="red", font=("simsun", 16))
self.statusStr.set('圆弧计算失败. 请调整计算点数后重试...')
self.log.error("arc calc exception." + errMsg)
return

xc_2, yc_2 = center_2
Ri_2 = calc_R(center_2)
R_2 = Ri_2.mean()
residu_2 = sum((Ri_2 - R_2) ** 2)

print('centerPoint x={},y={},r={}'.format(xc_2, yc_2, R_2))

pt['nameShow'] = pt['name'] + '\nr={:.4f}um'.format(R_2)
pt['annotate'].remove()
bbox = dict(boxstyle="round", fc="0.5")
pt['annotate'] = plt.annotate(pt['nameShow'],
xy=(pt['points'][0] + (pt['points'][2] - pt['points'][0]) / 2, pt['points'][1] + abs(pt['points'][3] - pt['points'][1]) / 3 * 2),
bbox=bbox, xytext=(0, 0), xycoords='data', textcoords='offset points', fontsize=12, ha='center')

if 'arc' in pt:
for it in pt['arc']:
it.remove()
self.canvas.draw_idle()
pt['arc'].clear()

line1, = ax1.plot(x, y, 'ro', label='data', ms=9, mec='b', mew=1)
pt['arc'].append(line1)

theta_fit = np.linspace(-np.pi, np.pi, 180)

x_fit2 = xc_2 + R_2 * np.cos(theta_fit)
y_fit2 = yc_2 + R_2 * np.sin(theta_fit)

# 拟合圆
line2, = ax1.plot(x_fit2, y_fit2, 'k--', label=method_2, lw=2)
pt['arc'].append(line2)

# 圆心
line3, = ax1.plot([xc_2], [yc_2], 'gD', mec='r', mew=1)
pt['arc'].append(line3)

self.ax.set_ymargin(0.3)
self.ax.autoscale(enable=True, tight=False)
self.ax.set_aspect('equal', adjustable='box', anchor='C')

self.canvas.draw_idle()
# python 脚本调用方式
draw_circle(df_point, ax1, plot_name_list, plot_list)

def draw_circle(df_calc,ax1,plot_name_list,plot_list):
x = df_calc['inner']
y = df_calc['height']

# x = [23.10770,23.11350,23.11770,23.12230,23.12610,23.13230]
# y = [5.19880,5.18250,5.16730,5.15070,5.13360,5.10250]

# coordinates of the barycenter
x_m = mean(x)
y_m = mean(y)

method_2 = "leastsq"

def calc_R(c):
""" calculate the distance of each 2D points from the center c=(xc, yc) """
return sqrt((x - c[0]) ** 2 + (y - c[1]) ** 2)

def calc_ecart(c):
""" calculate the algebraic distance between the 2D points and the mean circle centered at c=(xc, yc) """
Ri = calc_R(c)
return Ri - Ri.mean()

center_estimate = x_m, y_m
center_2, ier = optimize.leastsq(calc_ecart, center_estimate)

xc_2, yc_2 = center_2
Ri_2 = calc_R(center_2)
R_2 = Ri_2.mean()
residu_2 = sum((Ri_2 - R_2) ** 2)

print('x={},y={},r={}'.format(xc_2, yc_2, R_2))

# from matplotlib import pyplot as p, cm
#
# f = p.figure()

line2, = ax1.plot(x, y, 'ro', label='data', ms=9, mec='b', mew=1)
plot_name_list.append('circle orig')
plot_list.append(line2)

# p.plot(x, y, 'ro', label='data', ms=9, mec='b', mew=1)

theta_fit = linspace(-pi, pi, 180)

x_fit2 = xc_2 + R_2 * cos(theta_fit)
y_fit2 = yc_2 + R_2 * sin(theta_fit)
# p.plot(x_fit2, y_fit2, 'k--', label=method_2, lw=2)

line2, = ax1.plot(x_fit2, y_fit2, 'k--', label=method_2, lw=2)
plot_name_list.append('1 orig')
plot_list.append(line2)

# p.plot([xc_2], [yc_2], 'gD', mec='r', mew=1)
line2, = ax1.plot([xc_2], [yc_2], 'gD', mec='r', mew=1)
plot_name_list.append('2 orig')
plot_list.append(line2)

tkinter 有三种布局管理方式,注意不能混用:
pack
grid
place

发布程序

隐藏

frameobj.pack_forget() to hide
if you use frameobj.pack() to show

frameobj.grid_forget() to show
if you use frameobj.grid() to show
阅读全文 »

一般来说,频谱分析指的是将信号做傅里叶变换从而进行分析。频谱分析是包括幅频谱和相频谱两张图的。不过最常用的是幅频谱。

把时域的信息转换为频域表示,可以看出一些在时域状态下看不到的特征

滤波变得很容易,可以针对某个特征频率过滤

N个采样点,经过FFT之后,就可以得到N个点的FFT结果。为了方便进行FFT运算,通常N取2的整数次方。

阅读全文 »

self.chkProgMode = tk.IntVar()
tk.Checkbutton(topFrame2, text="设计模式", variable=self.chkProgMode, command=self.on_chk_ProgMode).pack(side=tk.LEFT, padx=4)

# 默认选择
self.chkProgMode.set(True)

显示、隐藏组件

self.buttonForget = tk.Button(self.root,
text = 'Click to hide Label',
command=lambda: self.label.pack_forget())
# We need to call the pack() method again to pack the widget to make it visible, or in other words, to recover it.

self.statusStr = tk.StringVar()
topFrame3 = tk.Frame()
self.status = tk.Label(topFrame3, textvariable=self.statusStr, fg="black", font=("simsun", 12),justify=tk.LEFT)
self.status.pack(side=tk.TOP)
self.statusStr.set('当前状态:准备...')
topFrame3.pack(side=tk.TOP)

# 动态修改颜色,字体
self.status.config(fg="red", font=("simsun", 16))
self.statusStr.set('当前状态:没有测量项可以计算,请先读取图形,载入测量项后计算...')
阅读全文 »

self.statusStr = tk.StringVar()
self.status = tk.Label(text='Ready...', textvariable=self.statusStr, bd=1, relief=tk.SUNKEN, anchor='w')
self.status.pack(side=tk.BOTTOM, fill=tk.X)

# modify text
self.statusStr.set('圆弧计算失败. 请调整计算点数后重试...')