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

Introduce a function for plotting z histograms in DESI EDR notebooks #194

Open
stephjuneau opened this issue Aug 24, 2023 · 0 comments · May be fixed by #207
Open

Introduce a function for plotting z histograms in DESI EDR notebooks #194

stephjuneau opened this issue Aug 24, 2023 · 0 comments · May be fixed by #207
Assignees
Labels
enhancement New feature or request

Comments

@stephjuneau
Copy link
Contributor

stephjuneau commented Aug 24, 2023

Suggestion from @rnikutta for a future revision of both DESI EDR tutorial notebooks. I'm marking it as an enhancement.

"This block is also very repetitive code:"

fig, axs = plt.subplots(4, 1, figsize = (9, 12))
bins = np.arange(0, 4, 0.2)

axs[0].hist(zpix_cat['z'][is_bgs], color = 'C0', bins = bins, label = f'BGS: {n_bgs} sources')
axs[0].legend(fontsize = 14)
axs[0].set_ylabel("N(z)")
axs[1].hist(zpix_cat['z'][is_lrg], color = 'C1', bins = bins, label = f'LRG: {n_lrg} sources')
axs[1].legend(fontsize = 14)
axs[1].set_ylabel("N(z)")
axs[2].hist(zpix_cat['z'][is_elg], color = 'C2', bins = bins, label = f'ELG: {n_elg} sources')
axs[2].legend(fontsize = 14)
axs[2].set_ylabel("N(z)")
axs[3].hist(zpix_cat['z'][is_qso], color = 'C3', bins = bins, label = f'QSO: {n_qso} sources')
axs[3].legend(fontsize = 14)
axs[3].set_ylabel("N(z)")
axs[3].set_xlabel("Redshift")

Why not introduce a tiny function that does the per-panel work? E.g.:

fig, axs = plt.subplots(4, 1, figsize = (9, 12))
bins = np.arange(0, 4, 0.2)

def plotaxis(axid,mask,color,cat):
    axs[axid].hist(zpix_cat['z'][mask], color = color, bins = bins, label = f'{cat}: {n_bgs} sources')
    axs[axid].legend(fontsize = 14)
    axs[axid].set_ylabel("N(z)")
    
plotaxis(0,is_bgs,'C0','BGS')
plotaxis(1,is_lrg,'C1','LRG')
plotaxis(2,is_elg,'C2','ELG')
plotaxis(3,is_qso,'C3','QSO')
axs[3].set_xlabel("Redshift")
@stephjuneau stephjuneau added the enhancement New feature or request label Aug 24, 2023
@Ragadeepika-Pucha Ragadeepika-Pucha linked a pull request Nov 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants