Skip to content

Commit 116501d

Browse files
committed
Add plot_forest and tests (arviz-devs#34)
* some improvements to PlotCollection * add classmethod tests * add more tests * add divergences to plot_trace * extend tests * add divergence data to test_plots * add plot_forest draft For everything to work, the following features were added to: * support for "__variable__" in aesthetics * default values for common aesthetics * support for dict of datatree input -> multiple models aligned within the same plot * add labels to plot_forest still some backend elements missing for bokeh * further improvements to plot_forest * invert y aes to preserve order top-down * improvements to aes_map defaults and shading * attempt support for InferenceData inputs * plot_dist support for multiple models and docs * update dependencies * add more tests * raise error on wrong use of combined * better support for aesthetics in labels elements
1 parent 39c3335 commit 116501d

File tree

20 files changed

+1762
-113
lines changed

20 files changed

+1762
-113
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.9", "3.10", "3.11"]
14+
python-version: ["3.10", "3.11", "3.12"]
1515
fail-fast: false
1616
steps:
1717
- uses: actions/checkout@v3

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# arviz-plots
22

3+
[![Run tests](https://github.com/arviz-devs/arviz-plots/actions/workflows/test.yml/badge.svg)](https://github.com/arviz-devs/arviz-plots/actions/workflows/test.yml)
4+
[![codecov](https://codecov.io/gh/arviz-devs/arviz-plots/graph/badge.svg?token=1VIPLXCOJQ)](https://codecov.io/gh/arviz-devs/arviz-plots)
35
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)
46

57
ArviZ plotting elements and static battery included plots

docs/source/api/backend/interface.template.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Plot appeareance
2626
title
2727
ylabel
2828
xlabel
29+
xticks
30+
yticks
2931
ticks_size
3032
remove_ticks
3133
remove_axis

docs/source/api/plots.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ A complementary introduction and guide to ``plot_...`` functions is available at
1616
:toctree: generated/
1717

1818
plot_dist
19+
plot_forest
1920
plot_trace
2021
plot_trace_dist

docs/source/api/visuals.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Data and axis annotating elements
2222
.. autosummary::
2323
:toctree: generated/
2424

25+
annotate_label
2526
point_estimate_text
2627
labelled_title
2728
labelled_y

docs/source/conf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"sphinx_copybutton",
3737
"sphinx_design",
3838
"jupyter_sphinx",
39+
"matplotlib.sphinxext.plot_directive",
3940
]
4041

4142
templates_path = ["_templates"]
@@ -67,11 +68,19 @@
6768

6869
# -- Options for extensions
6970

71+
plot_include_source = True
72+
plot_formats = [("png", 90)]
73+
plot_html_show_formats = False
74+
plot_html_show_source_link = False
75+
7076
extlinks = {
7177
"issue": ("https://github.com/arviz-devs/arviz-base/issues/%s", "GH#%s"),
7278
"pull": ("https://github.com/arviz-devs/arviz-base/pull/%s", "PR#%s"),
7379
}
7480

81+
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
82+
copybutton_prompt_is_regexp = True
83+
7584
nb_execution_mode = "auto"
7685
nb_execution_excludepatterns = ["*.ipynb"]
7786
nb_kernel_rgx_aliases = {".*": "python3"}
@@ -85,12 +94,13 @@
8594

8695
numpydoc_show_class_members = False
8796
numpydoc_xref_param_type = True
88-
numpydoc_xref_ignore = {"of", "or", "optional", "scalar"}
97+
numpydoc_xref_ignore = {"of", "or", "optional", "scalar", "default"}
8998
singulars = ("int", "list", "dict", "float")
9099
numpydoc_xref_aliases = {
91100
"DataArray": ":class:`xarray.DataArray`",
92101
"Dataset": ":class:`xarray.Dataset`",
93102
"DataTree": ":class:`datatree.DataTree`",
103+
"mapping": ":term:`python:mapping`",
94104
**{f"{singular}s": f":any:`{singular}s <{singular}>`" for singular in singulars},
95105
}
96106

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
name = "arviz-plots"
77
readme = "README.md"
8-
requires-python = ">=3.9"
8+
requires-python = ">=3.10"
99
license = {file = "LICENSE"}
1010
authors = [
1111
{name = "ArviZ team", email = "[email protected]"}
@@ -20,9 +20,9 @@ classifiers = [
2020
"Operating System :: OS Independent",
2121
"Programming Language :: Python",
2222
"Programming Language :: Python :: 3",
23-
"Programming Language :: Python :: 3.9",
2423
"Programming Language :: Python :: 3.10",
2524
"Programming Language :: Python :: 3.11",
25+
"Programming Language :: Python :: 3.12",
2626
]
2727
dynamic = ["version", "description"]
2828
dependencies = [
@@ -45,7 +45,8 @@ test = [
4545
"pytest",
4646
"pytest-cov",
4747
"matplotlib",
48-
"bokeh"
48+
"bokeh",
49+
"h5netcdf",
4950
]
5051
doc = [
5152
"furo",
@@ -110,6 +111,7 @@ disallow_untyped_defs = true
110111
# ignore_missing_imports = true
111112

112113
[tool.pytest.ini_options]
114+
filterwarnings = ["error"]
113115
testpaths = [
114116
"tests",
115117
]

src/arviz_plots/backend/__init__.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
to any type of the plotting backend or even custom objects, but all instances
1313
of the same placeholder must use the same type (whatever that is).
1414
"""
15+
import numpy as np
1516

1617
error = NotImplementedError(
1718
"The `arviz_plots.backend` module itself is for reference only. "
@@ -20,6 +21,22 @@
2021
)
2122

2223

24+
# generation of default values for aesthetics
25+
def get_default_aes(aes_key, n, kwargs):
26+
"""Generate `n` default values for a given aesthetics keyword."""
27+
if aes_key not in kwargs:
28+
if aes_key in {"x", "y"}:
29+
return np.arange(n)
30+
if aes_key == "alpha":
31+
return np.linspace(0.2, 0.7, n)
32+
return [None] * n
33+
aes_vals = kwargs[aes_key]
34+
n_aes_vals = len(aes_vals)
35+
if n_aes_vals >= n:
36+
return aes_vals[:n]
37+
return np.tile(aes_vals, (n // n_aes_vals) + 1)[:n]
38+
39+
2340
# object creation and i/o
2441
def show(chart):
2542
"""Show this :term:`chart`.
@@ -39,6 +56,8 @@ def create_plotting_grid(
3956
sharex=False,
4057
sharey=False,
4158
polar=False,
59+
width_ratios=None,
60+
plot_hspace=None,
4261
subplot_kws=None,
4362
**kwargs,
4463
):
@@ -56,6 +75,8 @@ def create_plotting_grid(
5675
Flags that indicate the axis limits between the different plots should
5776
be shared.
5877
polar : bool, default False
78+
width_ratios : array_like of shape (cols,), optional
79+
plot_hspace : float, optional
5980
subplot_kws, **kwargs : mapping, optional
6081
Arguments passed downstream to the plotting backend.
6182
@@ -114,9 +135,10 @@ def scatter(
114135
target : plot type
115136
size : float or array-like of float
116137
marker : any
138+
The character ``|`` must be a valid marker as it is the default for rug plots.
117139
alpha : float
118140
color : any
119-
Set both facecolor and edgecolor simultaneously.
141+
Set both facecolor and edgecolor simultaneously but without overriding them if present.
120142
facecolor : any
121143
Color of the marker filling.
122144
edgecolor : any
@@ -145,6 +167,11 @@ def text(
145167
raise error
146168

147169

170+
def fill_between_y(x, y_bottom, y_top, target, **artist_kws):
171+
"""Fill the region between y_bottom and y_top."""
172+
raise error
173+
174+
148175
# general plot appeareance
149176
def title(string, target, *, size=None, color=None, **artist_kws):
150177
"""Interface to adding a title to a plot."""
@@ -161,6 +188,32 @@ def xlabel(string, target, *, size=None, color=None, **artist_kws):
161188
raise error
162189

163190

191+
def xticks(ticks, labels, traget, **artist_kws):
192+
"""Interface to setting ticks and tick labels of the x axis.
193+
194+
Parameters
195+
----------
196+
ticks : array_like
197+
labels : array_like or None
198+
Labels for the provided `ticks`. Must accept ``None`` as a way
199+
to set only ticks and leave their default labels.
200+
"""
201+
raise error
202+
203+
204+
def yticks(ticks, labels, traget, **artist_kws):
205+
"""Interface to setting ticks and tick labels of the y axis.
206+
207+
Parameters
208+
----------
209+
ticks : array_like
210+
labels : array_like or None
211+
Labels for the provided `ticks`. Must accept ``None`` as a way
212+
to set only ticks and leave their default labels.
213+
"""
214+
raise error
215+
216+
164217
def ticks_size(value, target):
165218
"""Interface to setting ticks size."""
166219
raise error

0 commit comments

Comments
 (0)