Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich #111

Merged
merged 8 commits into from
Oct 11, 2024
Merged

Rich #111

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
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
Loading