Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate drawing to pandas #47

Open
bdrum opened this issue Jun 9, 2021 · 1 comment
Open

Migrate drawing to pandas #47

bdrum opened this issue Jun 9, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request software Issue dedicated to software

Comments

@bdrum
Copy link
Owner

bdrum commented Jun 9, 2021

Now I use such constructions for drawing:

bw, = ax.plot(np.linspace(x.min(), x.max(),1000), fit.bw(x=np.linspace(x.min(), x.max(),1000), M = result.best_values['bw_M'], G=result.best_values['bw_G'], amp=result.best_values['bw_amp'] ), 'g--',label=r'Breit-Wigner')
bkg, = plt.plot(np.linspace(x.min(), x.max(),1000), fit.polyn(np.linspace(x.min(), x.max(),1000), result.best_values['bckg_c0'], result.best_values['bckg_c1'], result.best_values['bckg_c2'], result.best_values['bckg_c3'], result.best_values['bckg_c4'],0,0,0, result.best_values['bckg_amp']), 'b--', label='Bckgr fit')
# plt.plot(bcg_x, bcg_y, 'r+', label='bkg data')
result.plot_fit(datafmt='ko',fitfmt='r-',numpoints=100,data_kws={'xerr':0.022})
ax.set_title('')
_ = ax.set_ylabel(r'Counts per 20 Mev/$c^2$')
_ = ax.set_xlabel(r'M$(\pi^+\pi^-\pi^+\pi^-)$ (GeV/$c^2$)')
_ = plt.legend([dat,ft, bw, bkg],['Data','Fit','Breit-Wigner','Bkg'])

Instead of this, I can combine data to DataFrames and use pandas plot for drawing purposes

@bdrum bdrum added enhancement New feature or request software Issue dedicated to software labels Jun 9, 2021
@bdrum bdrum self-assigned this Jun 9, 2021
@bdrum bdrum pinned this issue Jun 9, 2021
@bdrum
Copy link
Owner Author

bdrum commented Jun 18, 2021

E.g. this one

# data part
xx =  np.linspace(x.min(),x.max(),100)
ff =  result.eval(x=xx)
fbw1 = fit.bw(x=xx, M = result.best_values['bw1_M'],G=result.best_values['bw1_G'], amp=result.best_values['bw1_amp'] )
fbw2 = fit.bw(x=xx, M = result.best_values['bw2_M'],G=result.best_values['bw2_G'], amp=result.best_values['bw2_amp'] )
fbckg = fit.polyn(xx, result.best_values['bckg_c0'], result.best_values['bckg_c1'], result.best_values['bckg_c2'], result.best_values['bckg_c3'], result.best_values['bckg_c4'],0,0,0, result.best_values['bckg_amp'])
df=pd.DataFrame([xx,ff,fbw1,fbw2,fbckg]).T
df.columns=['x', 'fit', 'bw1','bw2', 'bkgr']
# drawing part
fig = plt.figure()
ax = fig.add_subplot()

dt, = hep.histplot(np.histogram(mass_events(kinematics.GetTracksWithPtCut(four_tracks_zq_after_all_cuts)), bins=b, range=r),ax=ax, yerr=True, xerr=0.022, color='black', histtype="errorbar",label='data')

ll = df.plot(x='x', y=['fit', 'bw1','bw2', 'bkgr'],ax=ax, style=['r-', 'g-', 'm-', 'b--'], xlabel=r'M($\pi^+\pi^-\pi^+\pi^-$) (GeV/$c^2$)', ylabel=r'Counts per 45 MeV/$c^2$')
_ = ax.legend([dt] + ll.get_children()[4:8], ['Data', 'Fit', 'Breit-Wigner', 'Breit-Wigner', 'Bkgr'])

bdrum added a commit that referenced this issue Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request software Issue dedicated to software
Projects
None yet
Development

No branches or pull requests

1 participant