Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Hist currently provides everything boost-histogram provides, and the following e
- Quick plotting routines encourage exploration:
- `.plot()` provides 1D and 2D plots
- `.plot2d_full()` shows 1D projects around a 2D plot
- `.plot_ratio(...)` make a ratio plot between the histogram and another histogram or callable
- `.plot_pull(...)` performs a pull plot
- `.plot_pie()` makes a pie plot
- `.show()` provides a nice str printout using Histoprint
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
IN PROGRESS
--------------------

* Add ``plot_ratio`` to the public API, which allows for making ratio plots between the
histogram and either another histogram or a callable.
`#161 <https://github.com/scikit-hep/hist/pull/161>`_

* Add frequentist coverage interval support in the ``intervals`` module.
`#176 <https://github.com/scikit-hep/hist/pull/176>`_

Expand Down
35 changes: 31 additions & 4 deletions src/hist/basehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import matplotlib.axes
from mplhep.plot import Hist1DArtists, Hist2DArtists

from .plot import FitResultArtists, MainAxisArtists, RatiolikeArtists

InnerIndexing = Union[
SupportsIndex, str, Callable[[bh.axis.Axis], int], slice, "ellipsis"
]
Expand Down Expand Up @@ -401,20 +403,45 @@ def plot2d_full(

return hist.plot.plot2d_full(self, ax_dict=ax_dict, **kwargs)

def plot_ratio(
self,
other: Union["hist.BaseHist", Callable[[np.ndarray], np.ndarray], str],
*,
ax_dict: "Optional[Dict[str, matplotlib.axes.Axes]]" = None,
**kwargs: Any,
) -> "Tuple[MainAxisArtists, RatiolikeArtists]":
"""
``plot_ratio`` method for ``BaseHist`` object.

Return a tuple of artists following a structure of
``(main_ax_artists, subplot_ax_artists)``
"""

import hist.plot

return hist.plot._plot_ratiolike(
self, other, ax_dict=ax_dict, view="ratio", **kwargs
)

def plot_pull(
self,
func: Callable[[np.ndarray], np.ndarray],
func: Union[Callable[[np.ndarray], np.ndarray], str],
*,
ax_dict: "Optional[Dict[str, matplotlib.axes.Axes]]" = None,
**kwargs: Any,
) -> "Tuple[matplotlib.axes.Axes, matplotlib.axes.Axes]":
) -> "Tuple[FitResultArtists, RatiolikeArtists]":
"""
Plot_pull method for BaseHist object.
``plot_pull`` method for ``BaseHist`` object.

Return a tuple of artists following a structure of
``(main_ax_artists, subplot_ax_artists)``
"""

import hist.plot

return hist.plot.plot_pull(self, func, ax_dict=ax_dict, **kwargs)
return hist.plot._plot_ratiolike(
self, func, ax_dict=ax_dict, view="pull", **kwargs
)

def plot_pie(
self,
Expand Down
Loading