mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling

https://github.com/scikit-hep/mplhep

Science Score: 64.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org, zenodo.org
  • Committers with academic emails
    13 of 44 committers (29.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.7%) to scientific vocabulary

Keywords

histograms matplotlib plotting python visualization

Keywords from Contributors

scikit-hep histogram hep closember cython fitting high-energy-physics jax spacy-extension root
Last synced: 4 months ago · JSON representation ·

Repository

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling

Basic Info
Statistics
  • Stars: 201
  • Watchers: 4
  • Forks: 69
  • Open Issues: 35
  • Releases: 48
Topics
histograms matplotlib plotting python visualization
Created over 6 years ago · Last pushed 4 months ago
Metadata Files
Readme Contributing License Citation

README.md

DOI Scikit-HEP Docs

Actions Status pre-commit.ci status pre-commit

PyPI version Conda-forge version Supported Python versions

PyPI download week

Binder

A set of helpers for matplotlib to more easily produce plots typically needed in HEP as well as style them in way that's compatible with current collaboration requirements (ROOT-like plots for CMS, ATLAS, LHCb, ALICE).

Installation

bash pip install mplhep

Getting Started

A tutorial given at PyHEP 2020 is available as a binder here or you can watch the recording here.

Documentation can be found at mplhep.readthedocs.io.

Styling

```python import mplhep as hep hep.style.use(hep.style.ROOT) # For now ROOT defaults to CMS

Or choose one of the experiment styles

hep.style.use(hep.style.ATLAS)

or

hep.style.use("CMS") # string aliases work too

{"ALICE" | "ATLAS" | "CMS" | "LHCb1" | "LHCb2" | "DUNE" | "DUNE1"}

```

Or use matplotlib API directly

python plt.style.use(hep.style.ROOT) If the default styles are not what you need, please open an issue.

Default experiment labels are also available.

```python

Overall - both left and right annotation

hep..label(, data=, lumi=50, year=2017)

Just experiment label and such as 'Preliminary' or 'Simulation'

hep..text() ```

You can use loc={0..5} to control the label positioning.

Plotting

1D Histograms

python h, bins = [2, 3, 2], [0, 1, 2, 3] hep.histplot(h, bins)

2D Histograms

python import numpy as np xbins, ybins = [0, 1, 2, 3], [0, 1, 2, 3] H = np.array([[2,3,2], [1,2,1], [3,1,3]]) hep.hist2dplot(H, xbins, ybins)

More Information

Save all labels at once

  • hep.savelabels('test.png') will produces 4 variation on experiment label
    • "" -> "test.png"
    • "Preliminary" -> "test_pas.png"
    • "Supplementary" -> "test_supp.png"
    • "Work in Progress" -> "test_wip.png"
  • Options can also be specified manually
    • hep.savelabels('test', labels=["FOO", "BAR"], suffixes=["foo.pdf", "bar"]) will produce
    • "FOO" -> "foo.pdf"
    • "BAR" -> "test_bar.png"
  • Other components of <experiment>.label() will remain unchanged.

Other styles:

  • hep.style.use("fira") - use Fira Sans
  • hep.style.use("firamath") - use Fira Math

Styles can be chained:

  • e.g. hep.style.use(["CMS", "fira", "firamath"])
  • reappearing rcParams get overwritten silently

Styles can be modified on the fly

  • Since styles are dictionaries and they can be chained/overwritten they can be easily modified on the fly. e.g. hep.style.use("CMS") hep.style.use({"font.sans-serif":'Comic Sans MS'})

Styling with LaTeX

  • hep.style.use("CMSTex") - Use LaTeX to produce all text labels
  • Requires having the full tex-live distro
  • True Helvetica
  • Use sansmath as the math font
  • Takes longer and not always better
  • In general more possibilities, but a bit more difficult to get everything working properly

Notes

Consistency & Fonts

As it is ROOT does not come with any fonts and therefore relies on using system fonts. Therefore the font in a figure can be dependent on whether it was produced on OSX or PC. The default sans-serif font used is Helvetica, but it only comes with OSX, in Windows this will silently fallback to Arial.

License

Both Helvetica and Arial are proprietary, which as far as fonts go means you can use it to create any text/graphics once you have the license, but you cannot redistribute the font files as part of other software. That means we cannot just package Helvetica with this to make sure everyone has the same font in plots.

Luckily for fonts it seems only the software is copyrighted, not the actual shapes, which means there are quite a few open alternatives with similar look. The most closely resembling Helvetica being Tex Gyre Heros

Tex Gyre Heros

http://www.gust.org.pl/projects/e-foundry/tex-gyre/heros

You can compare yourself if the differences are meanigful below.

They are Tex Gyre Heros, Helvetica and Arial respectively.

Math Fonts

  • Math fonts are a separate set from regular fonts due to the amount of special characters
  • It's not trivial to make sure you get a matching math font to your regular font
  • Most math-fonts are serif fonts, but this is not ideal if one wants to use sans-serif font for normal text like Helvetica or Arial
  • The number of sans-serif math-fonts is very limited
    • The number of open sans-serif math-fonts is extremely limited
    • Basically there's two, Fira Sans and GFS Neohellenic Math, of which I like Fira Sans better
    • https://tex.stackexchange.com/questions/374250/are-there-opentype-sans-math-fonts-under-development

For consistent styling Fira Sans is included as well.

Default Fira Sans

https://github.com/mozilla/Fira

Math font extension

https://github.com/firamath/firamath

What doesn't work

Context styles and fonts

python with pyplot.style.context(style.ROOT): plotting... - This syntax would be ideal, however, it doesn't work properly for fonts and there are no plans by mpl devs to fix this behaviour https://github.com/matplotlib/matplotlib/issues/11673

For now one has to set the style globally:

Use in publications

Updating list of citations and use cases of mplhep in publications:

Owner

  • Name: Scikit-HEP Project
  • Login: scikit-hep
  • Kind: organization
  • Email: scikit-hep-forum@googlegroups.com

A community project for High Energy Physics data analysis in Python

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
doi: "10.5281/zenodo.3766157"
date-released: "2020-04-25"
authors:
- family-names: "Novak"
  given-names: "Andrzej"
  affiliation: "RWTH Aachen"
  orcid: "https://orcid.org/0000-0002-0389-5896"
- family-names: "Schreiner"
  given-names: "Henry"
  affiliation: "Princeton University"
  orcid: "https://orcid.org/0000-0002-7833-783X"
- family-names: "Feickert"
  given-names: "Matthew"
  affiliation: "University of Wisconsin-Madison"
  orcid: "https://orcid.org/0000-0003-4124-7862"
- family-names: "Eschle"
  given-names: "Jonas"
  affiliation: "CERN"
  orcid: "https://orcid.org/0000-0002-7312-3699"
title: "mplhep"
url: "https://github.com/scikit-hep/mplhep"
keywords:
  - python
  - physics
  - matplotlib
  - visualization
  - plotting
  - scikit-hep
license: "MIT"

GitHub Events

Total
  • Create event: 42
  • Issues event: 10
  • Release event: 6
  • Watch event: 11
  • Delete event: 37
  • Issue comment event: 62
  • Push event: 145
  • Pull request review event: 26
  • Pull request review comment event: 18
  • Pull request event: 81
  • Fork event: 6
Last Year
  • Create event: 42
  • Issues event: 10
  • Release event: 6
  • Watch event: 11
  • Delete event: 37
  • Issue comment event: 62
  • Push event: 145
  • Pull request review event: 26
  • Pull request review comment event: 18
  • Pull request event: 81
  • Fork event: 6

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 726
  • Total Committers: 44
  • Avg Commits per committer: 16.5
  • Development Distribution Score (DDS): 0.439
Past Year
  • Commits: 61
  • Committers: 16
  • Avg Commits per committer: 3.813
  • Development Distribution Score (DDS): 0.656
Top Committers
Name Email Commits
andrzejnovak n****j@g****m 407
pre-commit-ci[bot] 6****] 82
GitHub Action a****n@g****m 70
Henry Schreiner h****i@g****m 57
Matthew Feickert m****t@c****h 43
Jonas Eschle j****e@c****h 10
Matthieu Marinangeli m****i@e****h 5
N!no n****l@g****m 4
Tristan Fillinger t****r@k****p 3
Cedric Verstege c****e@k****u 3
Andreas Albert a****t@c****h 3
Andreas Weiden a****n@g****m 2
Angus Hollands g****5@g****m 2
Austin Townsend a****2@n****u 2
Jeremy Wilkinson 7****3 2
Lindsey Gray l****y@g****m 2
Ming-Yan, Lee a****5@g****m 2
Sitian Qian s****n@c****h 1
Alexander Puck Neuwirth A****y 1
Balaji V Sathia Narayanan 4****n 1
Benkendorfer k****r@g****u 1
Chris Burr c****r 1
Zach Marshall z****l@g****m 1
Yi-Mu "Enoch" Chen 1****n 1
Victor Ruelas-Rivera r****h 1
Sébastien Wertz s****z 1
Raghav Kansal r****7@y****n 1
Peter Fackeldey p****y@r****e 1
Pedro Silva p****s 1
Louis Moureaux l****x@c****h 1
and 14 more...
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 63
  • Total pull requests: 275
  • Average time to close issues: 4 months
  • Average time to close pull requests: 23 days
  • Total issue authors: 39
  • Total pull request authors: 32
  • Average comments per issue: 1.63
  • Average comments per pull request: 1.18
  • Merged pull requests: 236
  • Bot issues: 2
  • Bot pull requests: 107
Past Year
  • Issues: 12
  • Pull requests: 95
  • Average time to close issues: 14 days
  • Average time to close pull requests: 3 days
  • Issue authors: 9
  • Pull request authors: 14
  • Average comments per issue: 0.42
  • Average comments per pull request: 0.72
  • Merged pull requests: 79
  • Bot issues: 2
  • Bot pull requests: 47
Top Authors
Issue Authors
  • andrzejnovak (13)
  • matthewfeickert (7)
  • jonas-eschle (6)
  • pre-commit-ci[bot] (2)
  • APN-Pucky (1)
  • lgray (1)
  • magnarex (1)
  • atownse2 (1)
  • alexander-held (1)
  • jpata (1)
  • GiorgosChr (1)
  • dantrim (1)
  • ikrommyd (1)
  • DManowitz (1)
  • GuillermoFidalgo (1)
Pull Request Authors
  • pre-commit-ci[bot] (104)
  • andrzejnovak (82)
  • henryiii (13)
  • jonas-eschle (13)
  • 0ctagon (7)
  • matthewfeickert (7)
  • cverstege (5)
  • Ming-Yan (5)
  • zlmarshall (3)
  • atownse2 (3)
  • jjhw3 (2)
  • asantra (2)
  • clelange (2)
  • yimuchen (2)
  • agoose77 (2)
Top Labels
Issue Labels
CI (2) good first issue (2) enhancement (2) docs (2) bug (1) question (1)
Pull Request Labels
bumpversion/patch (6) CI (3) test (2) enhancement (1) docs (1)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 555,001 last-month
  • Total docker downloads: 75,883
  • Total dependent packages: 25
    (may contain duplicates)
  • Total dependent repositories: 101
    (may contain duplicates)
  • Total versions: 214
  • Total maintainers: 4
pypi.org: mplhep

Matplotlib styles for HEP

  • Versions: 151
  • Dependent Packages: 20
  • Dependent Repositories: 85
  • Downloads: 555,001 Last month
  • Docker Downloads: 75,883
Rankings
Dependent packages count: 0.6%
Docker downloads count: 1.1%
Dependent repos count: 1.6%
Downloads: 1.9%
Average: 2.8%
Forks count: 5.6%
Stargazers count: 5.6%
Maintainers (2)
Last synced: 4 months ago
spack.io: py-mplhep

Matplotlib styles for HEP

  • Versions: 8
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 14.9%
Forks count: 15.5%
Stargazers count: 16.0%
Dependent packages count: 28.1%
Maintainers (1)
Last synced: 4 months ago
conda-forge.org: mplhep
  • Versions: 54
  • Dependent Packages: 4
  • Dependent Repositories: 16
Rankings
Dependent repos count: 8.9%
Dependent packages count: 12.5%
Average: 19.1%
Forks count: 25.5%
Stargazers count: 29.6%
Last synced: 5 months ago
pypi.org: embedded-mplhep

Matplotlib styles for HEP

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.4%
Average: 38.3%
Dependent repos count: 69.2%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/cd.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact v3 composite
  • pypa/gh-action-pypi-publish v1.5.1 composite
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
.github/workflows/head-dependencies.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
docs/requirements.txt pypi
  • matplotlib >=3.2
  • mplhep_data *
  • numpy >=1.16.0
  • packaging *
  • uhi >=0.2.0
pyproject.toml pypi
setup.py pypi