mplhep
Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
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
Keywords from Contributors
Repository
Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
Basic Info
- Host: GitHub
- Owner: scikit-hep
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://mplhep.readthedocs.io
- Size: 12.2 MB
Statistics
- Stars: 201
- Watchers: 4
- Forks: 69
- Open Issues: 35
- Releases: 48
Topics
Metadata Files
README.md
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.
Just experiment label and such as 'Preliminary' or 'Simulation'
hep.
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 Sanshep.style.use("firamath")- use Fira Math
Styles can be chained:
- e.g.
hep.style.use(["CMS", "fira", "firamath"]) - reappearing
rcParamsget 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:
- Simultaneous Jet Energy and Mass Calibrations with Neural Networks, ATLAS Collaboration, 2019
- Integration and Performance of New Technologies in the CMS Simulation, Kevin Pedro, 2020 (Fig 5,6)
- GeantV: Results from the prototype of concurrent vector particle transport simulation in HEP, Amadio et al, 2020 (Fig 25,26)
- Search for the standard model Higgs boson decaying to charm quarks, CMS Collaboration, 2019 (Fig 1)
- Search for long-lived particles decaying to eμν, LHCb Collaboration, 2020
- Measurement of the mass dependence of the transverse momentum of lepton pairs in Drell-Yan production in proton-proton collisions at √s = 13 TeV, CMS Collaboration, 2022 (Figs 3-)
- And many others by now...
Owner
- Name: Scikit-HEP Project
- Login: scikit-hep
- Kind: organization
- Email: scikit-hep-forum@googlegroups.com
- Website: https://scikit-hep.org
- Repositories: 46
- Profile: https://github.com/scikit-hep
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
Top Committers
| Name | 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
Pull Request Labels
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
- Homepage: https://github.com/scikit-hep/mplhep
- Documentation: https://mplhep.readthedocs.io/
- License: MIT License
-
Latest release: 0.4.1
published 4 months ago
Rankings
Maintainers (2)
spack.io: py-mplhep
Matplotlib styles for HEP
- Homepage: https://github.com/scikit-hep/mplhep
- License: []
-
Latest release: 0.4.0
published 4 months ago
Rankings
Maintainers (1)
conda-forge.org: mplhep
- Homepage: https://github.com/scikit-hep/mplhep
- License: MIT
-
Latest release: 0.3.26
published over 3 years ago
Rankings
pypi.org: embedded-mplhep
Matplotlib styles for HEP
- Homepage: https://github.com/scikit-hep/mplhep
- Documentation: https://embedded-mplhep.readthedocs.io/
- License: MIT
-
Latest release: 0.5.13
published over 2 years ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/upload-artifact v3 composite
- pypa/gh-action-pypi-publish v1.5.1 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- matplotlib >=3.2
- mplhep_data *
- numpy >=1.16.0
- packaging *
- uhi >=0.2.0