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

plt.yscale and mplhep.histplot / histogram log scale on y? #94

Closed
ryuwd opened this issue Mar 4, 2020 · 4 comments
Closed

plt.yscale and mplhep.histplot / histogram log scale on y? #94

ryuwd opened this issue Mar 4, 2020 · 4 comments

Comments

@ryuwd
Copy link

ryuwd commented Mar 4, 2020

Hi All,
Very glad to see there are people dedicated to making matplotlib a suitable plotting solution for HEP data.

I have a problem with setting a log scale on the y-axis when plotting a pre-binned histogram (uproot reads variable from root tree --> np.histogram)

Am I missing something or doing something wrong here?

    plt.figure(figsize=(6,6))
    hep.histplot(histnom[0], histnom[1], label='Nominal')
    hep.histplot(histmisal[0], histmisal[1], label='Misaligned')
    plt.legend(fontsize='x-small')
    plt.gca().xaxis.set_minor_locator(AutoMinorLocator())
    plt.gca().yaxis.set_minor_locator(AutoMinorLocator())
    plt.title("Momentum resolution (deent)", fontsize=16)
    plt.xlabel("$p - p_{MC}$ [MeV]", fontsize=14)
    plt.ylabel("Tracks / %.1f MeV" % (bin_sz), fontsize=14)
    plt.yticks(fontsize=14)
    plt.xticks(fontsize=14)
    plt.yscale('log')

Here is the produced plot:
ylogscale

Works without plt.yscale

@andrzejnovak
Copy link
Member

andrzejnovak commented Mar 5, 2020

Hmm, I should fix that, but you can get around it by setting ylim to a small non-zero number. The problem is histplot automatically sets lower ylim to 0, because it makes sense for a histogram, but I am not sure if there's an automated solution to this since the function won't know when it's called that it will be a log plot in your example

@ryuwd
Copy link
Author

ryuwd commented Mar 5, 2020

Ah, this sounds like a good idea - I will try this soon and let you know how it looks.

Thanks!

@andrzejnovak
Copy link
Member

@ryuwd Fixed in #150

@ryuwd
Copy link
Author

ryuwd commented Jun 21, 2020

Apologies I didn't follow up - but I did manage to get it working after your suggestion. Thanks for fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants