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

fix: legend linestyle for step histogram #496

Merged
merged 3 commits into from
Apr 30, 2024

Conversation

8me
Copy link

@8me 8me commented Apr 28, 2024

The legend entries for mplhep.histplot for histtype='step' shows always continuous entires no matter what linestyle arg is defined. In order to fix that the linestyle is forwarded to _e_leg and xerr is set to None as it is not used in the step mode.

@andrzejnovak
Copy link
Member

Hi @8me thanks for the PR! I think I understand the change, but could you add a picture here just for posterity?

@8me
Copy link
Author

8me commented Apr 30, 2024

@andrzejnovak Here we go 😉 ... ok I created this example script:

#!/usr/bin/env python
# coding=utf-8
# Filename: test.py
"""
MPLHEP testplot script

"""
import mplhep
import numpy as np
import matplotlib.pyplot as plt

BINS = np.linspace(0, 1, 10)


def main():
    samples = np.random.normal(loc=0.5, scale=0.1, size=1000)
    wgts = np.random.rand(1000)
    h = np.histogram(samples, bins=BINS, weights=wgts)
    h2 = np.histogram(samples, bins=BINS, weights=wgts**2)
    fig, ax = plt.subplots()
    mplhep.histplot(h, w2=h2[0], linestyle=':', ax=ax, label="Test Hist")
    ax.legend()
    plt.savefig("new.pdf")


if __name__ == '__main__':
    main()

So with the current master the legend for a histogram with linestyle=':' looks like:
old
... with the changes on this PR it would look like:
new

@andrzejnovak andrzejnovak changed the title Legend linestyle for step histogram fix: legend linestyle for step histogram Apr 30, 2024
@andrzejnovak andrzejnovak merged commit f6c9542 into scikit-hep:master Apr 30, 2024
8 of 9 checks passed
@andrzejnovak
Copy link
Member

Perfect, thanks for the PR!

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

Successfully merging this pull request may close these issues.

2 participants