物理学会2025@広島大学
物理学会に参加してきました。サッカーもできて、いろいろな人と打ち合わせもでき、やはり良い会合だなと思いました。 オンサイトは年一回なので、記憶に残りやすいです。
import numpy as np
import matplotlib.pyplot as plt
import scipy
from scipy.optimize import curve_fit
from scipy.signal import savgol_filter
config = {
'lines.linewidth':1.5,
'xtick.direction': 'in',
'ytick.direction': 'in',
'font.sans-serif': ['Helvetica', 'Arial'],
'font.family': ['sans-serif'],
'font.size': 14,
'figure.dpi': 200,
'legend.fontsize': 'small', # 'medium',
'figure.figsize': [8, 5],
'lines.markersize': 3.0,
'legend.frameon': True,
'savefig.transparent': True,
'lines.markeredgewidth': 0.7,
'lines.markerfacecolor': 'w',
'legend.edgecolor': '0',
'legend.facecolor': [1, 1, 1],
'legend.framealpha': 1
# plt.rcParams.keys()
}
plt.rcParams.update(config)
def fun(t, a, b, tau):
return a * np.sin(b * t) * np.exp(- t * tau)
dp = 3000
x = np.arange(dp)
ra = 0.1 * np.random.randn(dp)
y = fun(x, 1, 0.003, 0.0008)+ ra
f = plt.figure()
ax1 = f.add_axes([0.2, 0.2, 0.6, 0.6])
ax1.set_xlabel('$t$ (ms)')
ax1.set_ylabel('$V$ (mV)')
ax1.set_xlim(-100, 3100)
ax1.set_ylim(-1., 1.5)
ax1.plot(x, y, marker = 'o', linestyle = '', color = [0.5, 0.5, 1], label = 'raw data')
ynew = savgol_filter(y, 11, 3)
x1 = x[::10]
y1 = ynew[::10]
ax1.plot(x1, y1, 'b-', linewidth = 2, label = 'smoothed data')
popt, pcov = curve_fit(fun, x, y, bounds = ([0.8, 0.002, 0.0005], [1.2, 0.004, 0.001]))
ax1.plot(x, fun(x, *popt), 'r-', linewidth = 2, label = 'curve_fit')
print(popt)
ax1.legend()
[9.88442022e-01 3.00238180e-03 7.91843009e-04]
<matplotlib.legend.Legend at 0x7f98e66dc100>
コメント
コメントを投稿