179 def calibrate_plot(fig, Xlist, preds, datas, errs, text=None, title=None, labels=None):
180 if not isinstance(preds, list):
183 if not isinstance(datas, list):
186 if not isinstance(Xlist, list):
189 assert(len(preds) == len(datas) == len(Xlist))
191 gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])
192 ax1 = fig.subplot(gs[0])
193 ax2 = fig.subplot(gs[1], sharex = ax1)
195 colors = fig.rcParams[
'axes.prop_cycle'].by_key()[
'color']
201 color =
None if len(preds) == 1
else colors[i]
203 if labels
is not None:
204 label = label +
" " + labels[i]
205 p = ax1.plot(Xs, pred, label=label, color=color)
208 for i, (Xs, data, err)
in enumerate(
zip(Xlist, datas, errs)):
209 color =
None if len(preds) == 1
else colors[i]
210 label =
"Data M.P.V."
211 if labels
is not None:
212 label = label +
" " + labels[i]
213 d = ax1.errorbar(Xs, data, yerr=err, ls=
"none",
214 color=color, label=label, marker=
".", markersize=5.)
217 leg_labels = [
"Fit/Data" for _
in ps]
218 if labels
is not None:
219 leg_labels = [ll+l
for ll,l
in zip(leg_labels, labels)]
221 ax1.legend(
list(
zip(ps, ds)), leg_labels, numpoints=1,
222 handler_map={tuple: HandlerTuple(ndivide=
None)})
224 ax2.set_label(
"Residual Range [cm]")
225 ax1.set_ylabel(
"dQ/dx [ADDC/cm]")
228 ax1.text(0.5, 2.25, text, transform=fig.gca().transAxes, verticalalignment=
"top")
232 ax1.get_shared_x_axes().
join(ax1, ax2)
233 fig.subplots_adjust(hspace=.0)
235 for i, (Xs, data, pred, err)
in enumerate(
zip(Xlist, datas, preds, errs)):
236 color =
None if len(preds) == 1
else colors[i]
237 ax2.plot(Xs, (data - pred) / err, color=color)
239 ax2.set_ylim([-4, 4])
240 ax2.axhline(0, color=
"gray")
241 ax2.axhline(1, color=
"gray", linestyle=
"--")
242 ax2.axhline(-1, color=
"gray", linestyle=
"--")
243 ax2.axhline(2, color=
"gray", linestyle=
":")
244 ax2.axhline(-2, color=
"gray", linestyle=
":")
245 ax2.set_ylabel(
"Data - Pred. [$\\sigma$]")
246 ax2.set_xlabel(
"Residual Range [cm]")
248 yticks = ax2.yaxis.get_major_ticks()
249 yticks[-1].label1.set_visible(
False)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.