behaviz 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- behaviz/__init__.py +110 -0
- behaviz/backends/__init__.py +11 -0
- behaviz/backends/_legend.py +22 -0
- behaviz/backends/_save.py +40 -0
- behaviz/backends/bokeh/__init__.py +12 -0
- behaviz/backends/bokeh/backend.py +610 -0
- behaviz/backends/bokeh/hover_engine.py +67 -0
- behaviz/backends/bokeh/overrider.py +196 -0
- behaviz/backends/hover.py +84 -0
- behaviz/backends/matplotlib/__init__.py +12 -0
- behaviz/backends/matplotlib/backend.py +227 -0
- behaviz/backends/matplotlib/hover_engine.py +106 -0
- behaviz/backends/matplotlib/overrider.py +201 -0
- behaviz/backends/override.py +122 -0
- behaviz/backends/renderer.py +116 -0
- behaviz/backends/renderer_manager.py +32 -0
- behaviz/backends/renderer_registry.py +38 -0
- behaviz/backends/seaborn/__init__.py +12 -0
- behaviz/backends/seaborn/backend.py +315 -0
- behaviz/backends/seaborn/hover_engine.py +14 -0
- behaviz/backends/seaborn/overrider.py +227 -0
- behaviz/cli.py +68 -0
- behaviz/composite_plots/boxplot.py +108 -0
- behaviz/composite_plots/hist1dplot.py +87 -0
- behaviz/composite_plots/lollipopplot.py +65 -0
- behaviz/composite_plots/parallelplot.py +93 -0
- behaviz/composite_plots/raincloudplot.py +144 -0
- behaviz/composite_plots/styling.py +67 -0
- behaviz/core/__init__.py +18 -0
- behaviz/core/auxiliary.py +75 -0
- behaviz/core/channels.py +228 -0
- behaviz/core/context.py +43 -0
- behaviz/core/core.py +478 -0
- behaviz/core/core_factory.py +133 -0
- behaviz/core/data_source.py +76 -0
- behaviz/core/errors.py +81 -0
- behaviz/core/grouping.py +263 -0
- behaviz/core/palette.py +56 -0
- behaviz/core/plot_registry.py +163 -0
- behaviz/core/plot_setup.py +180 -0
- behaviz/core/registry_validation.py +74 -0
- behaviz/io.py +105 -0
- behaviz/manipulations/__init__.py +5 -0
- behaviz/manipulations/binner.py +73 -0
- behaviz/manipulations/dodger.py +120 -0
- behaviz/manipulations/jitter.py +94 -0
- behaviz/manipulations/manipulator.py +270 -0
- behaviz/manipulations/normaliser.py +53 -0
- behaviz/manipulations/smoother.py +43 -0
- behaviz/presets.py +309 -0
- behaviz/spec/__init__.py +4 -0
- behaviz/spec/_style_presets.py +180 -0
- behaviz/spec/axis_spec.py +37 -0
- behaviz/spec/colorbar_spec.py +58 -0
- behaviz/spec/figure_spec.py +20 -0
- behaviz/spec/plot_spec.py +206 -0
- behaviz/spec/serialization.py +117 -0
- behaviz-0.4.0.dist-info/METADATA +1400 -0
- behaviz-0.4.0.dist-info/RECORD +63 -0
- behaviz-0.4.0.dist-info/WHEEL +5 -0
- behaviz-0.4.0.dist-info/entry_points.txt +2 -0
- behaviz-0.4.0.dist-info/licenses/LICENSE +674 -0
- behaviz-0.4.0.dist-info/top_level.txt +1 -0
behaviz/__init__.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from importlib.metadata import version as _version, PackageNotFoundError
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
__version__ = _version("behaviz")
|
|
5
|
+
except PackageNotFoundError: # not installed (e.g. running from source tree)
|
|
6
|
+
__version__ = "0.0.0+unknown"
|
|
7
|
+
|
|
8
|
+
# Plot functions
|
|
9
|
+
from behaviz.core.core import (
|
|
10
|
+
plot_line,
|
|
11
|
+
plot_scatter,
|
|
12
|
+
plot_errorbar,
|
|
13
|
+
plot_violin,
|
|
14
|
+
plot_step,
|
|
15
|
+
plot_bar,
|
|
16
|
+
plot_vertical,
|
|
17
|
+
plot_horizontal,
|
|
18
|
+
plot_image,
|
|
19
|
+
plot_fill_between,
|
|
20
|
+
plot_pie,
|
|
21
|
+
plot_hexbin,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from behaviz.core.auxiliary import plot_pval
|
|
25
|
+
|
|
26
|
+
# Errors (malformed data arguments, and unsupported save formats)
|
|
27
|
+
from behaviz.core.errors import BehavizDataError, BehavizSaveError
|
|
28
|
+
|
|
29
|
+
# Unified figure output (save + canvas context manager)
|
|
30
|
+
from behaviz.io import save, canvas
|
|
31
|
+
|
|
32
|
+
# Spec classes (users need these to configure plots)
|
|
33
|
+
from behaviz.spec.plot_spec import PlotSpec
|
|
34
|
+
from behaviz.spec.axis_spec import AxisSpec, ScaleType
|
|
35
|
+
from behaviz.spec.figure_spec import FigureSpec, LegendPosition
|
|
36
|
+
from behaviz.spec.colorbar_spec import ColorbarSpec
|
|
37
|
+
|
|
38
|
+
# Preset save/load system
|
|
39
|
+
from behaviz.presets import (
|
|
40
|
+
load_preset,
|
|
41
|
+
save_preset,
|
|
42
|
+
list_presets,
|
|
43
|
+
delete_preset,
|
|
44
|
+
export_preset,
|
|
45
|
+
import_preset,
|
|
46
|
+
init_home,
|
|
47
|
+
presets_dir,
|
|
48
|
+
examples_dir,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# composite plot styling helper
|
|
52
|
+
from behaviz.composite_plots.styling import split_styles
|
|
53
|
+
|
|
54
|
+
# Visual manipulations
|
|
55
|
+
import behaviz.manipulations
|
|
56
|
+
|
|
57
|
+
# Backend switcher
|
|
58
|
+
import behaviz.backends
|
|
59
|
+
from behaviz.backends.renderer_manager import set_renderer, get_renderer
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
__all__ = [
|
|
63
|
+
# plot functions
|
|
64
|
+
"plot_line",
|
|
65
|
+
"plot_scatter",
|
|
66
|
+
"plot_errorbar",
|
|
67
|
+
"plot_violin",
|
|
68
|
+
"plot_step",
|
|
69
|
+
"plot_bar",
|
|
70
|
+
"plot_rain",
|
|
71
|
+
"plot_vertical",
|
|
72
|
+
"plot_horizontal",
|
|
73
|
+
"plot_image",
|
|
74
|
+
"plot_fill_between",
|
|
75
|
+
"plot_pie",
|
|
76
|
+
"plot_hexbin",
|
|
77
|
+
"plot_distribution",
|
|
78
|
+
"plot_psychometric",
|
|
79
|
+
"plot_impact",
|
|
80
|
+
"plot_pval",
|
|
81
|
+
# errors
|
|
82
|
+
"BehavizDataError",
|
|
83
|
+
"BehavizSaveError",
|
|
84
|
+
# figure output
|
|
85
|
+
"save",
|
|
86
|
+
"canvas",
|
|
87
|
+
# specs
|
|
88
|
+
"PlotSpec",
|
|
89
|
+
"AxisSpec",
|
|
90
|
+
"ScaleType",
|
|
91
|
+
"FigureSpec",
|
|
92
|
+
"LegendPosition",
|
|
93
|
+
"ColorbarSpec",
|
|
94
|
+
# presets
|
|
95
|
+
"load_preset",
|
|
96
|
+
"save_preset",
|
|
97
|
+
"list_presets",
|
|
98
|
+
"delete_preset",
|
|
99
|
+
"export_preset",
|
|
100
|
+
"import_preset",
|
|
101
|
+
"init_home",
|
|
102
|
+
"presets_dir",
|
|
103
|
+
"examples_dir",
|
|
104
|
+
# backend
|
|
105
|
+
"set_renderer",
|
|
106
|
+
"get_renderer",
|
|
107
|
+
"__version__",
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
set_renderer("matplotlib")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import behaviz.backends.matplotlib
|
|
2
|
+
import behaviz.backends.seaborn
|
|
3
|
+
import behaviz.backends.bokeh # noqa: F401
|
|
4
|
+
|
|
5
|
+
# Validate that every registered plot type is fully implemented across all
|
|
6
|
+
# backends and overriders. This runs once at import and raises immediately if
|
|
7
|
+
# anything is missing, so errors surface during development rather than at
|
|
8
|
+
# call time.
|
|
9
|
+
from behaviz.core.registry_validation import validate_registry
|
|
10
|
+
|
|
11
|
+
validate_registry()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Shared legend helper for the matplotlib-based backends."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def dedup_legend(handles_labels):
|
|
7
|
+
"""Drop repeated labels (keeping the first) from ``get_legend_handles_labels()``.
|
|
8
|
+
|
|
9
|
+
Grouped/hued plots can attach the same label to several artists — e.g. every
|
|
10
|
+
rectangle of a bar container, or one line per subject sharing a hue label —
|
|
11
|
+
which would otherwise produce duplicate legend entries.
|
|
12
|
+
"""
|
|
13
|
+
handles, labels = handles_labels
|
|
14
|
+
seen: set = set()
|
|
15
|
+
h_out, l_out = [], []
|
|
16
|
+
for h, l in zip(handles, labels):
|
|
17
|
+
if l in seen:
|
|
18
|
+
continue
|
|
19
|
+
seen.add(l)
|
|
20
|
+
h_out.append(h)
|
|
21
|
+
l_out.append(l)
|
|
22
|
+
return h_out, l_out
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Shared figure-saving helpers for the matplotlib-based backends.
|
|
2
|
+
|
|
3
|
+
``SeabornRenderer`` is not a subclass of ``MatplotlibRenderer``, so the common
|
|
4
|
+
``fig.savefig`` logic lives here as free functions both can call.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
from behaviz.core.errors import BehavizSaveError
|
|
12
|
+
|
|
13
|
+
# Raster/vector formats matplotlib's Agg/PDF/SVG/PS writers handle.
|
|
14
|
+
MPL_FORMATS = frozenset({".png", ".pdf", ".svg", ".jpg", ".jpeg", ".tif", ".tiff", ".eps", ".ps"})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def extension(path) -> str:
|
|
18
|
+
"""Lower-cased file extension of ``path`` (including the dot)."""
|
|
19
|
+
return os.path.splitext(os.fspath(path))[1].lower()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def save_matplotlib(fig, path, **kwargs) -> str:
|
|
23
|
+
"""Write a matplotlib ``Figure`` to ``path``, dispatching on its extension."""
|
|
24
|
+
ext = extension(path)
|
|
25
|
+
if ext in MPL_FORMATS:
|
|
26
|
+
kwargs.setdefault("bbox_inches", "tight")
|
|
27
|
+
fig.savefig(path, **kwargs)
|
|
28
|
+
return os.fspath(path)
|
|
29
|
+
|
|
30
|
+
if ext in (".html", ".htm"):
|
|
31
|
+
raise BehavizSaveError(
|
|
32
|
+
"The matplotlib/seaborn backend cannot write HTML. Use a raster or "
|
|
33
|
+
"vector format (.png, .pdf, .svg), or switch to the bokeh backend "
|
|
34
|
+
"for interactive HTML output."
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
raise BehavizSaveError(
|
|
38
|
+
f"Unsupported file format '{ext or path}' for the matplotlib/seaborn backend. "
|
|
39
|
+
f"Supported: {', '.join(sorted(MPL_FORMATS))}."
|
|
40
|
+
)
|