diff --git a/notebooks/Jungfrau/Jungfrau_gain_Spectra_Fit_Summary_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_gain_Spectra_Fit_Summary_NBC.ipynb index c83406c3551447adecbb707f9f358074aa2f84f9..78b78c9db54ff37839b84b1e0af9aef98a3a06c2 100644 --- a/notebooks/Jungfrau/Jungfrau_gain_Spectra_Fit_Summary_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_gain_Spectra_Fit_Summary_NBC.ipynb @@ -113,15 +113,27 @@ "plt.show()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Histogram data for all cells for each module" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "fixed_cols = 4\n", - "fig, axs = plt.subplots(\n", - " math.ceil(nmods / fixed_cols), 4, figsize=(20, 10)) # Adjust for spatial histograms\n", + "if nmods > 4:\n", + " fixed_cols = 4\n", + " row, col = math.ceil(nmods / fixed_cols), 4\n", + "else:\n", + " row, col = 1, nmods\n", + "\n", + "fig, axs = plt.subplots(row, col, figsize=(20, 10)) # Adjust for spatial histograms\n", + "axs = axs.ravel()\n", "for i, da in enumerate (da_to_pdu.keys()):\n", " with h5file(\n", " Path(out_folder) / histo_temp.format(run, proposal.upper(), da),\n", @@ -131,17 +143,16 @@ " row, col = divmod(i, 4)\n", " for m in range(histos.shape[1]):\n", " cell_hist = histos[m]\n", - " axs[row, col].plot(cell_hist.ravel(), label=f'Cell {m}')\n", - " axs[row, col].set_title(f\"{da} ({da_to_pdu[da]})\")\n", + " axs[i].plot(cell_hist.ravel(), label=f'Cell {m}')\n", + " axs[i].set_title(f\"{da} ({da_to_pdu[da]})\")\n", "\n", - "for i, ax in enumerate(axs.flat):\n", - " if i > nmods:\n", + "for i, ax in enumerate(axs):\n", + " if i > nmods-1:\n", " ax.set_visible(False) # Hide unused subplots\n", "# Create a legend for the whole figure\n", - "handles, labels = axs[0, 0].get_legend_handles_labels()\n", - "fig.legend(handles, labels, loc=\"center right\")\n", - "plt.title(\"Histogram for all cell for each module.\")\n", - "plt.tight_layout()\n", + "handles, labels = axs[0].get_legend_handles_labels()\n", + "fig.legend(handles, labels, loc=\"center right\" if nmods > 4 else \"upper right\")\n", + "plt.tight_layout(pad=3)\n", "plt.show()" ] }