hsf-training / hsf-training-matplotlib

Create commonly used plots in HEP with matplotlib and mplhep
https://hsf-training.github.io/hsf-training-matplotlib/
Other
4 stars 9 forks source link

Reduce redundancy with keyword-argument dictionaries #77

Open klieret opened 2 years ago

klieret commented 2 years ago

Example in episode 4:

fig, (ax_1, ax_2) = plt.subplots(1, 2)
fig.set_size_inches((12, 8))
ax_1.set_title("MC samples without weights")
ax_1.hist(stack_mc_list_m4l, range=ranges[0], label=mc_samples, stacked=True, bins=bins)
ax_1.set_ylabel("Events")
ax_1.set_xlabel(var_name+units)
ax_1.legend(frameon=False)
ax_2.set_title("MC samples with weights")
ax_2.hist(stack_mc_list_m4l, range=rangos[0], label=mc_samples, stacked=True, weights=stack_weights_list, bins=bines)
ax_2.set_ylabel("Events")
ax_2.set_xlabel(var_name+units)
ax_2.tick_params(which="both",direction="in",top=True,right=True, length=6, width=1)
ax_2.legend(frameon=False)

just define

hist_kwargs = dict(stacked=True, bins=bins, ...)

ax_1.hist(..., **hist_kwargs)
stale[bot] commented 1 year ago

This issue or pull request has been automatically marked as stale because it has not had recent activity. Please manually close it, if it is no longer relevant, or ask for help or support to help getting it unstuck. Let me bring this to the attention of @klieret @wdconinc @michmx for now.