Skip to content
Draft
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
4 changes: 3 additions & 1 deletion src/physt/examples/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

python -m physt.examples
"""
import importlib
import importlib.util
import sys

from rich.json import JSON
Expand Down Expand Up @@ -37,6 +37,8 @@
h1.plot(backend="ascii", show_values=True, color="green")
console.print()

h1.plot(backend="plotext", kind="hbar")

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

Expand Down
6 changes: 6 additions & 0 deletions src/physt/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
backends["folium"] = folium_backend


with suppress(KeyError):
from . import plotext as plotext_backend

backends["plotext"] = plotext_backend


backends["ascii"] = ascii_backend

_default_backend: Optional[str] = None
Expand Down
35 changes: 35 additions & 0 deletions src/physt/plotting/plotext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import typing

import plotext as plt

if typing.TYPE_CHECKING:
from physt.types import Histogram1D


types: typing.Tuple[str, ...] = ("bar", "hbar")


dims = {
"hbar": [1],
"bar": [1],
}


def hbar(
h1: "Histogram1D",
) -> None:
fig = plt.active()
x = h1.bin_centers
y = h1.frequencies
fig.monitor.draw_bar(x, y, orientation="horizontal")
plt.show()


def bar(
h1: "Histogram1D",
) -> None:
fig = plt.active()
x = h1.bin_centers
y = h1.frequencies
fig.monitor.draw_bar(x, y, orientation="vertical")
plt.show()
Loading