Skip to content

hist can be installed and used in JupyterLite, but plotting with Matplotlib doesn't work #573

@jpivarski

Description

@jpivarski

Code cell contents

import piplite
await piplite.install("mplhep")
await piplite.install("hist")
from hist import Hist
h = Hist.new.Reg(10, -5, 5).Double()
h

image

(good)

h.plot()
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[5], line 1
----> 1 h.plot()

File /lib/python3.11/site-packages/hist/basehist.py:479, in BaseHist.plot(self, overlay, *args, **kwargs)
    476 _project = _has_categorical or overlay is not None
    478 if self.ndim == 1 or (self.ndim == 2 and _project):
--> 479     return self.plot1d(*args, overlay=overlay, **kwargs)
    481 if self.ndim == 2:
    482     return self.plot2d(*args, **kwargs)

File /lib/python3.11/site-packages/hist/basehist.py:497, in BaseHist.plot1d(self, ax, overlay, **kwargs)
    486 def plot1d(
    487     self,
    488     *,
   (...)
    491     **kwargs: Any,
    492 ) -> Hist1DArtists:
    493     """
    494     Plot1d method for BaseHist object.
    495     """
--> 497     from hist import plot
    499     if self.ndim == 1:
    500         return plot.histplot(self, ax=ax, **_proc_kw_for_lw(kwargs))

File /lib/python3.11/site-packages/hist/plot.py:17
     15     import matplotlib.pyplot as plt
     16     from matplotlib import patches, transforms
---> 17     from mplhep.plot import Hist1DArtists, Hist2DArtists, hist2dplot, histplot
     18 except ModuleNotFoundError:
     19     print(  # noqa: T201
     20         "Hist requires mplhep to plot, either install hist[plot] or mplhep",
     21         file=sys.stderr,
     22     )

File /lib/python3.11/site-packages/mplhep/__init__.py:10
      6 import mplhep_data
      8 # Get styles directly, also available within experiment helpers.
      9 # Get helper functions
---> 10 from . import alice, atlas, cms, label, lhcb, plot
     11 from . import styles as style
     12 from ._tools import Config

File /lib/python3.11/site-packages/mplhep/alice.py:8
      5 import mplhep
      7 from . import label as label_base
----> 8 from ._compat import docstring
      9 from .label import lumitext
     11 # Log styles

File /lib/python3.11/site-packages/mplhep/_compat.py:3
      1 from __future__ import annotations
----> 3 from matplotlib import _docstring as docstring  # type: ignore[attr-defined]
      5 __all__ = ("docstring",)

ImportError: cannot import name '_docstring' from 'matplotlib' (/lib/python3.11/site-packages/matplotlib/__init__.py)

(bad)

Screenshot directly copied from JupyterLite

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions