Skip to content

Commit

Permalink
Add possibility of choosing legend location
Browse files Browse the repository at this point in the history
  • Loading branch information
fchinu committed Oct 21, 2024
1 parent 16cf4dc commit 281d1fc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions flarefly/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ def plot_mass_fit(self, **kwargs):
- extra_info_loc: list
location of extra info (one for chi2 and one for other info)
- legend_loc: str
location of the legend
- num: int
number of bins to plot pdfs converted into histograms
Expand All @@ -1482,7 +1485,8 @@ def plot_mass_fit(self, **kwargs):
mass_range = kwargs.get('extra_info_massrange', None)
nhwhm = kwargs.get('extra_info_massnhwhm', None)
nsigma = kwargs.get('extra_info_massnsigma', 3)
loc = kwargs.get('extra_info_loc', ['upper left', 'lower right'])
info_loc = kwargs.get('extra_info_loc', ['lower right', 'upper left'])
legend_loc = kwargs.get('legend_loc', 'best')

mplhep.style.use(style)

Expand Down Expand Up @@ -1537,7 +1541,6 @@ def plot_mass_fit(self, **kwargs):
plt.xlim(limits[0], limits[1])
plt.xlabel(axis_title)
plt.ylabel(rf'counts / {(limits[1]-limits[0])/bins*1000:0.1f} MeV/$c^2$')
plt.legend(loc='best')
if logy:
plt.yscale('log')
plt.ylim(min(total_func) * norm_total_pdf / 5, max(total_func) * norm_total_pdf * 5)
Expand All @@ -1549,7 +1552,7 @@ def plot_mass_fit(self, **kwargs):
chi2 = self.get_chi2()
ndf = self.get_ndf()
anchored_text_chi2 = AnchoredText(fr'$\chi^2 / \mathrm{{ndf}} =${chi2:.2f} / {ndf}',
loc = loc[0],
loc = info_loc[0],
frameon=False)
# signal and background info for all signals
text = []
Expand Down Expand Up @@ -1597,11 +1600,13 @@ def plot_mass_fit(self, **kwargs):
extra_info += fr' Signif.$({nsigma}\sigma)=${signif:.1f} $\pm$ {signif_err:.1f}'
text.append(extra_info)
concatenated_text = '\n'.join(text)
anchored_text_signal = AnchoredText(concatenated_text, loc = loc[1], frameon=False)
anchored_text_signal = AnchoredText(concatenated_text, loc = info_loc[1], frameon=False)

axs.add_artist(anchored_text_chi2)
axs.add_artist(anchored_text_signal)

plt.legend(loc=legend_loc)

Logger('plot_mass_fit now returns a tuple (fig, axs) !', 'WARNING')

return fig, axs
Expand Down

0 comments on commit 281d1fc

Please sign in to comment.