Skip to content

Commit

Permalink
Merge pull request #111 from janpipek/rich
Browse files Browse the repository at this point in the history
Rich
  • Loading branch information
janpipek authored Oct 11, 2024
2 parents a00ab11 + 61369a5 commit 709f283
Show file tree
Hide file tree
Showing 5 changed files with 1,630 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ build:

publish: build
uv publish

examples:
uv run --extra all python -m physt.examples
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ In short, whatever you want to do with histograms, **physt** aims to be on your
[![Anaconda-Server Badge](https://anaconda.org/janpipek/physt/badges/license.svg)](https://anaconda.org/janpipek/physt)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## See it in action

With [`uv`](https://docs.astral.sh/uv/) installed, you can run the following command without needing to install
anything to see some examples in action:

```bash
uv run --with "physt[terminal]>=0.8.3" -m physt.examples
```

## Simple example

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ plotly = ["plotly"]
# TODO: Re-enable vega?
# vega3 = ["vega3"]
folium = ["folium"]
# TODO: Update to uproot4?
# root = ["uproot3"]
xtermcolor = ["xtermcolor"]
# root = ["uproot3"] # TODO: Update to uproot4
terminal = ["xtermcolor", "rich"]
all = [
"physt[astropy,dev,dask,pandas,polars,xarray,matplotlib,plotly,folium,xtermcolor]",
"physt[astropy,dev,dask,pandas,polars,xarray,matplotlib,plotly,folium,terminal]"
]

[build-system]
Expand Down
48 changes: 48 additions & 0 deletions src/physt/examples/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Script showing some of the physt examples.
You can run this like:
python -m physt.examples
"""
import importlib
import sys

from rich.json import JSON
from rich.panel import Panel

if not importlib.util.find_spec("rich"):
print("Please, install rich or physt[terminal] to view nice terminal output.")
sys.exit(-1)

from rich.console import Console

from physt.examples import normal_h1, normal_h2

console = Console()


h1 = normal_h1()
h2 = normal_h2()

console.print("[bold]A 1D histogram:[/bold]")
console.print(h1)

console.print()
console.print("[bold]The associated stats:[/bold]")
console.print(h1.statistics)

console.print()
console.print("[bold]And the plot:[/bold]")

h1.plot(backend="ascii", show_values=True)
console.print()

console.print("[bold]JSON fully describing the histogram:[/bold]")
console.print(Panel(JSON(h1.to_json()), width=min(console.width, 60)))

console.print("[bold]A 2D histogram:[/bold]")
console.print(h2)

console.print()
console.print("[bold]And the plot:[/bold]")
h2.plot(backend="ascii")
Loading

0 comments on commit 709f283

Please sign in to comment.