arviz 0.23.3__py3-none-any.whl → 1.0.0rc0__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.
- arviz/__init__.py +52 -367
- arviz-1.0.0rc0.dist-info/METADATA +182 -0
- arviz-1.0.0rc0.dist-info/RECORD +5 -0
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/WHEEL +1 -2
- {arviz-0.23.3.dist-info → arviz-1.0.0rc0.dist-info}/licenses/LICENSE +0 -1
- arviz/data/__init__.py +0 -55
- arviz/data/base.py +0 -596
- arviz/data/converters.py +0 -203
- arviz/data/datasets.py +0 -161
- arviz/data/example_data/code/radon/radon.json +0 -326
- arviz/data/example_data/data/centered_eight.nc +0 -0
- arviz/data/example_data/data/non_centered_eight.nc +0 -0
- arviz/data/example_data/data_local.json +0 -12
- arviz/data/example_data/data_remote.json +0 -58
- arviz/data/inference_data.py +0 -2386
- arviz/data/io_beanmachine.py +0 -112
- arviz/data/io_cmdstan.py +0 -1036
- arviz/data/io_cmdstanpy.py +0 -1233
- arviz/data/io_datatree.py +0 -23
- arviz/data/io_dict.py +0 -462
- arviz/data/io_emcee.py +0 -317
- arviz/data/io_json.py +0 -54
- arviz/data/io_netcdf.py +0 -68
- arviz/data/io_numpyro.py +0 -497
- arviz/data/io_pyjags.py +0 -378
- arviz/data/io_pyro.py +0 -333
- arviz/data/io_pystan.py +0 -1095
- arviz/data/io_zarr.py +0 -46
- arviz/data/utils.py +0 -139
- arviz/labels.py +0 -210
- arviz/plots/__init__.py +0 -61
- arviz/plots/autocorrplot.py +0 -171
- arviz/plots/backends/__init__.py +0 -223
- arviz/plots/backends/bokeh/__init__.py +0 -166
- arviz/plots/backends/bokeh/autocorrplot.py +0 -101
- arviz/plots/backends/bokeh/bfplot.py +0 -23
- arviz/plots/backends/bokeh/bpvplot.py +0 -193
- arviz/plots/backends/bokeh/compareplot.py +0 -167
- arviz/plots/backends/bokeh/densityplot.py +0 -239
- arviz/plots/backends/bokeh/distcomparisonplot.py +0 -23
- arviz/plots/backends/bokeh/distplot.py +0 -183
- arviz/plots/backends/bokeh/dotplot.py +0 -113
- arviz/plots/backends/bokeh/ecdfplot.py +0 -73
- arviz/plots/backends/bokeh/elpdplot.py +0 -203
- arviz/plots/backends/bokeh/energyplot.py +0 -155
- arviz/plots/backends/bokeh/essplot.py +0 -176
- arviz/plots/backends/bokeh/forestplot.py +0 -772
- arviz/plots/backends/bokeh/hdiplot.py +0 -54
- arviz/plots/backends/bokeh/kdeplot.py +0 -268
- arviz/plots/backends/bokeh/khatplot.py +0 -163
- arviz/plots/backends/bokeh/lmplot.py +0 -185
- arviz/plots/backends/bokeh/loopitplot.py +0 -211
- arviz/plots/backends/bokeh/mcseplot.py +0 -184
- arviz/plots/backends/bokeh/pairplot.py +0 -328
- arviz/plots/backends/bokeh/parallelplot.py +0 -81
- arviz/plots/backends/bokeh/posteriorplot.py +0 -324
- arviz/plots/backends/bokeh/ppcplot.py +0 -379
- arviz/plots/backends/bokeh/rankplot.py +0 -149
- arviz/plots/backends/bokeh/separationplot.py +0 -107
- arviz/plots/backends/bokeh/traceplot.py +0 -436
- arviz/plots/backends/bokeh/violinplot.py +0 -164
- arviz/plots/backends/matplotlib/__init__.py +0 -124
- arviz/plots/backends/matplotlib/autocorrplot.py +0 -72
- arviz/plots/backends/matplotlib/bfplot.py +0 -78
- arviz/plots/backends/matplotlib/bpvplot.py +0 -177
- arviz/plots/backends/matplotlib/compareplot.py +0 -135
- arviz/plots/backends/matplotlib/densityplot.py +0 -194
- arviz/plots/backends/matplotlib/distcomparisonplot.py +0 -119
- arviz/plots/backends/matplotlib/distplot.py +0 -178
- arviz/plots/backends/matplotlib/dotplot.py +0 -116
- arviz/plots/backends/matplotlib/ecdfplot.py +0 -70
- arviz/plots/backends/matplotlib/elpdplot.py +0 -189
- arviz/plots/backends/matplotlib/energyplot.py +0 -113
- arviz/plots/backends/matplotlib/essplot.py +0 -180
- arviz/plots/backends/matplotlib/forestplot.py +0 -656
- arviz/plots/backends/matplotlib/hdiplot.py +0 -48
- arviz/plots/backends/matplotlib/kdeplot.py +0 -177
- arviz/plots/backends/matplotlib/khatplot.py +0 -241
- arviz/plots/backends/matplotlib/lmplot.py +0 -149
- arviz/plots/backends/matplotlib/loopitplot.py +0 -144
- arviz/plots/backends/matplotlib/mcseplot.py +0 -161
- arviz/plots/backends/matplotlib/pairplot.py +0 -355
- arviz/plots/backends/matplotlib/parallelplot.py +0 -58
- arviz/plots/backends/matplotlib/posteriorplot.py +0 -348
- arviz/plots/backends/matplotlib/ppcplot.py +0 -478
- arviz/plots/backends/matplotlib/rankplot.py +0 -119
- arviz/plots/backends/matplotlib/separationplot.py +0 -97
- arviz/plots/backends/matplotlib/traceplot.py +0 -526
- arviz/plots/backends/matplotlib/tsplot.py +0 -121
- arviz/plots/backends/matplotlib/violinplot.py +0 -148
- arviz/plots/bfplot.py +0 -128
- arviz/plots/bpvplot.py +0 -308
- arviz/plots/compareplot.py +0 -177
- arviz/plots/densityplot.py +0 -284
- arviz/plots/distcomparisonplot.py +0 -197
- arviz/plots/distplot.py +0 -233
- arviz/plots/dotplot.py +0 -233
- arviz/plots/ecdfplot.py +0 -372
- arviz/plots/elpdplot.py +0 -174
- arviz/plots/energyplot.py +0 -147
- arviz/plots/essplot.py +0 -319
- arviz/plots/forestplot.py +0 -304
- arviz/plots/hdiplot.py +0 -211
- arviz/plots/kdeplot.py +0 -357
- arviz/plots/khatplot.py +0 -236
- arviz/plots/lmplot.py +0 -380
- arviz/plots/loopitplot.py +0 -224
- arviz/plots/mcseplot.py +0 -194
- arviz/plots/pairplot.py +0 -281
- arviz/plots/parallelplot.py +0 -204
- arviz/plots/plot_utils.py +0 -599
- arviz/plots/posteriorplot.py +0 -298
- arviz/plots/ppcplot.py +0 -369
- arviz/plots/rankplot.py +0 -232
- arviz/plots/separationplot.py +0 -167
- arviz/plots/styles/arviz-bluish.mplstyle +0 -1
- arviz/plots/styles/arviz-brownish.mplstyle +0 -1
- arviz/plots/styles/arviz-colors.mplstyle +0 -2
- arviz/plots/styles/arviz-cyanish.mplstyle +0 -1
- arviz/plots/styles/arviz-darkgrid.mplstyle +0 -40
- arviz/plots/styles/arviz-doc.mplstyle +0 -88
- arviz/plots/styles/arviz-docgrid.mplstyle +0 -88
- arviz/plots/styles/arviz-grayscale.mplstyle +0 -41
- arviz/plots/styles/arviz-greenish.mplstyle +0 -1
- arviz/plots/styles/arviz-orangish.mplstyle +0 -1
- arviz/plots/styles/arviz-plasmish.mplstyle +0 -1
- arviz/plots/styles/arviz-purplish.mplstyle +0 -1
- arviz/plots/styles/arviz-redish.mplstyle +0 -1
- arviz/plots/styles/arviz-royish.mplstyle +0 -1
- arviz/plots/styles/arviz-viridish.mplstyle +0 -1
- arviz/plots/styles/arviz-white.mplstyle +0 -40
- arviz/plots/styles/arviz-whitegrid.mplstyle +0 -40
- arviz/plots/traceplot.py +0 -273
- arviz/plots/tsplot.py +0 -440
- arviz/plots/violinplot.py +0 -192
- arviz/preview.py +0 -58
- arviz/py.typed +0 -0
- arviz/rcparams.py +0 -606
- arviz/sel_utils.py +0 -223
- arviz/static/css/style.css +0 -340
- arviz/static/html/icons-svg-inline.html +0 -15
- arviz/stats/__init__.py +0 -37
- arviz/stats/density_utils.py +0 -1013
- arviz/stats/diagnostics.py +0 -1013
- arviz/stats/ecdf_utils.py +0 -324
- arviz/stats/stats.py +0 -2422
- arviz/stats/stats_refitting.py +0 -119
- arviz/stats/stats_utils.py +0 -609
- arviz/tests/__init__.py +0 -1
- arviz/tests/base_tests/__init__.py +0 -1
- arviz/tests/base_tests/test_data.py +0 -1679
- arviz/tests/base_tests/test_data_zarr.py +0 -143
- arviz/tests/base_tests/test_diagnostics.py +0 -511
- arviz/tests/base_tests/test_diagnostics_numba.py +0 -87
- arviz/tests/base_tests/test_helpers.py +0 -18
- arviz/tests/base_tests/test_labels.py +0 -69
- arviz/tests/base_tests/test_plot_utils.py +0 -342
- arviz/tests/base_tests/test_plots_bokeh.py +0 -1288
- arviz/tests/base_tests/test_plots_matplotlib.py +0 -2197
- arviz/tests/base_tests/test_rcparams.py +0 -317
- arviz/tests/base_tests/test_stats.py +0 -925
- arviz/tests/base_tests/test_stats_ecdf_utils.py +0 -166
- arviz/tests/base_tests/test_stats_numba.py +0 -45
- arviz/tests/base_tests/test_stats_utils.py +0 -384
- arviz/tests/base_tests/test_utils.py +0 -376
- arviz/tests/base_tests/test_utils_numba.py +0 -87
- arviz/tests/conftest.py +0 -46
- arviz/tests/external_tests/__init__.py +0 -1
- arviz/tests/external_tests/test_data_beanmachine.py +0 -78
- arviz/tests/external_tests/test_data_cmdstan.py +0 -398
- arviz/tests/external_tests/test_data_cmdstanpy.py +0 -496
- arviz/tests/external_tests/test_data_emcee.py +0 -166
- arviz/tests/external_tests/test_data_numpyro.py +0 -434
- arviz/tests/external_tests/test_data_pyjags.py +0 -119
- arviz/tests/external_tests/test_data_pyro.py +0 -260
- arviz/tests/external_tests/test_data_pystan.py +0 -307
- arviz/tests/helpers.py +0 -677
- arviz/utils.py +0 -773
- arviz/wrappers/__init__.py +0 -13
- arviz/wrappers/base.py +0 -236
- arviz/wrappers/wrap_pymc.py +0 -36
- arviz/wrappers/wrap_stan.py +0 -148
- arviz-0.23.3.dist-info/METADATA +0 -264
- arviz-0.23.3.dist-info/RECORD +0 -183
- arviz-0.23.3.dist-info/top_level.txt +0 -1
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"""Bokeh hdiplot."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
|
|
5
|
-
from ...plot_utils import _scale_fig_size, vectorized_to_hex
|
|
6
|
-
from .. import show_layout
|
|
7
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def plot_hdi(ax, x_data, y_data, color, figsize, plot_kwargs, fill_kwargs, backend_kwargs, show):
|
|
11
|
-
"""Bokeh HDI plot."""
|
|
12
|
-
if backend_kwargs is None:
|
|
13
|
-
backend_kwargs = {}
|
|
14
|
-
|
|
15
|
-
backend_kwargs = {
|
|
16
|
-
**backend_kwarg_defaults(),
|
|
17
|
-
**backend_kwargs,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
plot_kwargs = {} if plot_kwargs is None else plot_kwargs
|
|
21
|
-
plot_kwargs["color"] = vectorized_to_hex(plot_kwargs.get("color", color))
|
|
22
|
-
plot_kwargs.setdefault("alpha", 0)
|
|
23
|
-
|
|
24
|
-
fill_kwargs = {} if fill_kwargs is None else fill_kwargs.copy()
|
|
25
|
-
# Convert matplotlib color to bokeh fill_color if needed
|
|
26
|
-
if "color" in fill_kwargs and "fill_color" not in fill_kwargs:
|
|
27
|
-
fill_kwargs["fill_color"] = vectorized_to_hex(fill_kwargs.pop("color"))
|
|
28
|
-
else:
|
|
29
|
-
fill_kwargs["fill_color"] = vectorized_to_hex(fill_kwargs.get("fill_color", color))
|
|
30
|
-
fill_kwargs.setdefault("fill_alpha", fill_kwargs.pop("alpha", 0.5))
|
|
31
|
-
|
|
32
|
-
figsize, *_ = _scale_fig_size(figsize, None)
|
|
33
|
-
|
|
34
|
-
if ax is None:
|
|
35
|
-
ax = create_axes_grid(
|
|
36
|
-
1,
|
|
37
|
-
figsize=figsize,
|
|
38
|
-
squeeze=True,
|
|
39
|
-
backend_kwargs=backend_kwargs,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
plot_kwargs.setdefault("line_color", plot_kwargs.pop("color"))
|
|
43
|
-
plot_kwargs.setdefault("line_alpha", plot_kwargs.pop("alpha", 0))
|
|
44
|
-
|
|
45
|
-
ax.patch(
|
|
46
|
-
np.concatenate((x_data, x_data[::-1])),
|
|
47
|
-
np.concatenate((y_data[:, 0], y_data[:, 1][::-1])),
|
|
48
|
-
**fill_kwargs,
|
|
49
|
-
**plot_kwargs
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
show_layout(ax, show)
|
|
53
|
-
|
|
54
|
-
return ax
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
# pylint: disable=c-extension-no-member
|
|
2
|
-
"""Bokeh KDE Plot."""
|
|
3
|
-
from collections.abc import Callable
|
|
4
|
-
from numbers import Integral
|
|
5
|
-
|
|
6
|
-
import numpy as np
|
|
7
|
-
from bokeh.models import ColumnDataSource
|
|
8
|
-
from bokeh.models.glyphs import Scatter
|
|
9
|
-
from matplotlib import colormaps
|
|
10
|
-
from matplotlib.colors import rgb2hex
|
|
11
|
-
from matplotlib.pyplot import rcParams as mpl_rcParams
|
|
12
|
-
|
|
13
|
-
from ...plot_utils import _scale_fig_size, _init_kwargs_dict
|
|
14
|
-
from .. import show_layout
|
|
15
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def plot_kde(
|
|
19
|
-
density,
|
|
20
|
-
lower,
|
|
21
|
-
upper,
|
|
22
|
-
density_q,
|
|
23
|
-
xmin,
|
|
24
|
-
xmax,
|
|
25
|
-
ymin,
|
|
26
|
-
ymax,
|
|
27
|
-
gridsize,
|
|
28
|
-
values,
|
|
29
|
-
values2,
|
|
30
|
-
rug,
|
|
31
|
-
label, # pylint: disable=unused-argument
|
|
32
|
-
quantiles,
|
|
33
|
-
rotated,
|
|
34
|
-
contour,
|
|
35
|
-
fill_last,
|
|
36
|
-
figsize,
|
|
37
|
-
textsize, # pylint: disable=unused-argument
|
|
38
|
-
plot_kwargs,
|
|
39
|
-
fill_kwargs,
|
|
40
|
-
rug_kwargs,
|
|
41
|
-
contour_kwargs,
|
|
42
|
-
contourf_kwargs,
|
|
43
|
-
pcolormesh_kwargs,
|
|
44
|
-
is_circular, # pylint: disable=unused-argument
|
|
45
|
-
ax,
|
|
46
|
-
legend, # pylint: disable=unused-argument
|
|
47
|
-
backend_kwargs,
|
|
48
|
-
show,
|
|
49
|
-
return_glyph,
|
|
50
|
-
):
|
|
51
|
-
"""Bokeh kde plot."""
|
|
52
|
-
backend_kwargs = _init_kwargs_dict(backend_kwargs)
|
|
53
|
-
|
|
54
|
-
backend_kwargs = {
|
|
55
|
-
**backend_kwarg_defaults(),
|
|
56
|
-
**backend_kwargs,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
figsize, *_ = _scale_fig_size(figsize, textsize)
|
|
60
|
-
|
|
61
|
-
if ax is None:
|
|
62
|
-
ax = create_axes_grid(
|
|
63
|
-
1,
|
|
64
|
-
figsize=figsize,
|
|
65
|
-
squeeze=True,
|
|
66
|
-
backend_kwargs=backend_kwargs,
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
glyphs = []
|
|
70
|
-
if values2 is None:
|
|
71
|
-
plot_kwargs = _init_kwargs_dict(plot_kwargs)
|
|
72
|
-
plot_kwargs.setdefault("line_color", mpl_rcParams["axes.prop_cycle"].by_key()["color"][0])
|
|
73
|
-
|
|
74
|
-
fill_kwargs = _init_kwargs_dict(fill_kwargs)
|
|
75
|
-
fill_kwargs.setdefault("fill_color", mpl_rcParams["axes.prop_cycle"].by_key()["color"][0])
|
|
76
|
-
|
|
77
|
-
if rug:
|
|
78
|
-
rug_kwargs = _init_kwargs_dict(rug_kwargs)
|
|
79
|
-
|
|
80
|
-
if "cds" in rug_kwargs:
|
|
81
|
-
cds_rug = rug_kwargs.pop("cds")
|
|
82
|
-
rug_varname = rug_kwargs.pop("y", "y")
|
|
83
|
-
else:
|
|
84
|
-
rug_varname = "y"
|
|
85
|
-
cds_rug = ColumnDataSource({rug_varname: np.asarray(values)})
|
|
86
|
-
|
|
87
|
-
rug_kwargs.setdefault("size", 8)
|
|
88
|
-
rug_kwargs.setdefault("line_color", plot_kwargs["line_color"])
|
|
89
|
-
rug_kwargs.setdefault("line_width", 1)
|
|
90
|
-
rug_kwargs.setdefault("line_alpha", 0.35)
|
|
91
|
-
if not rotated:
|
|
92
|
-
rug_kwargs.setdefault("angle", np.pi / 2)
|
|
93
|
-
if isinstance(cds_rug, dict):
|
|
94
|
-
for _cds_rug in cds_rug.values():
|
|
95
|
-
if not rotated:
|
|
96
|
-
glyph = Scatter(x=rug_varname, y=0.0, marker="dash", **rug_kwargs)
|
|
97
|
-
else:
|
|
98
|
-
glyph = Scatter(x=0.0, y=rug_varname, marker="dash", **rug_kwargs)
|
|
99
|
-
ax.add_glyph(_cds_rug, glyph)
|
|
100
|
-
else:
|
|
101
|
-
if not rotated:
|
|
102
|
-
glyph = Scatter(x=rug_varname, y=0.0, marker="dash", **rug_kwargs)
|
|
103
|
-
else:
|
|
104
|
-
glyph = Scatter(x=0.0, y=rug_varname, marker="dash", **rug_kwargs)
|
|
105
|
-
ax.add_glyph(cds_rug, glyph)
|
|
106
|
-
glyphs.append(glyph)
|
|
107
|
-
|
|
108
|
-
x = np.linspace(lower, upper, len(density))
|
|
109
|
-
|
|
110
|
-
if quantiles is not None:
|
|
111
|
-
fill_kwargs.setdefault("fill_alpha", 0.75)
|
|
112
|
-
fill_kwargs.setdefault("line_color", None)
|
|
113
|
-
|
|
114
|
-
quantiles = sorted(np.clip(quantiles, 0, 1))
|
|
115
|
-
if quantiles[0] != 0:
|
|
116
|
-
quantiles = [0] + quantiles
|
|
117
|
-
if quantiles[-1] != 1:
|
|
118
|
-
quantiles = quantiles + [1]
|
|
119
|
-
|
|
120
|
-
for quant_0, quant_1 in zip(quantiles[:-1], quantiles[1:]):
|
|
121
|
-
idx = (density_q > quant_0) & (density_q < quant_1)
|
|
122
|
-
if idx.sum():
|
|
123
|
-
patch_x = np.concatenate((x[idx], [x[idx][-1]], x[idx][::-1], [x[idx][0]]))
|
|
124
|
-
patch_y = np.concatenate(
|
|
125
|
-
(np.zeros_like(density[idx]), [density[idx][-1]], density[idx][::-1], [0])
|
|
126
|
-
)
|
|
127
|
-
if not rotated:
|
|
128
|
-
patch = ax.patch(patch_x, patch_y, **fill_kwargs)
|
|
129
|
-
else:
|
|
130
|
-
patch = ax.patch(patch_y, patch_x, **fill_kwargs)
|
|
131
|
-
glyphs.append(patch)
|
|
132
|
-
else:
|
|
133
|
-
if fill_kwargs.get("fill_alpha", False):
|
|
134
|
-
patch_x = np.concatenate((x, [x[-1]], x[::-1], [x[0]]))
|
|
135
|
-
patch_y = np.concatenate(
|
|
136
|
-
(np.zeros_like(density), [density[-1]], density[::-1], [0])
|
|
137
|
-
)
|
|
138
|
-
if not rotated:
|
|
139
|
-
patch = ax.patch(patch_x, patch_y, **fill_kwargs)
|
|
140
|
-
else:
|
|
141
|
-
patch = ax.patch(patch_y, patch_x, **fill_kwargs)
|
|
142
|
-
glyphs.append(patch)
|
|
143
|
-
|
|
144
|
-
if label is not None:
|
|
145
|
-
plot_kwargs.setdefault("legend_label", label)
|
|
146
|
-
if not rotated:
|
|
147
|
-
line = ax.line(x, density, **plot_kwargs)
|
|
148
|
-
else:
|
|
149
|
-
line = ax.line(density, x, **plot_kwargs)
|
|
150
|
-
glyphs.append(line)
|
|
151
|
-
|
|
152
|
-
else:
|
|
153
|
-
try:
|
|
154
|
-
import contourpy
|
|
155
|
-
except ImportError as err:
|
|
156
|
-
raise ImportError(
|
|
157
|
-
"'bokeh' kde contour plots needs ContourPy installed (pip install countourpy)."
|
|
158
|
-
) from err
|
|
159
|
-
|
|
160
|
-
contour_kwargs = _init_kwargs_dict(contour_kwargs)
|
|
161
|
-
contourf_kwargs = _init_kwargs_dict(contourf_kwargs)
|
|
162
|
-
pcolormesh_kwargs = _init_kwargs_dict(pcolormesh_kwargs)
|
|
163
|
-
|
|
164
|
-
g_s = complex(gridsize[0])
|
|
165
|
-
x_x, y_y = np.mgrid[xmin:xmax:g_s, ymin:ymax:g_s]
|
|
166
|
-
|
|
167
|
-
if contour:
|
|
168
|
-
scaled_density, *scaled_density_args = _scale_axis(density)
|
|
169
|
-
|
|
170
|
-
contourpy_kwargs = _init_kwargs_dict(contour_kwargs.pop("contourpy_kwargs", {}))
|
|
171
|
-
contourpy_kwargs.setdefault("name", "serial")
|
|
172
|
-
contour_generator = contourpy.contour_generator(
|
|
173
|
-
x=x_x, y=y_y, z=scaled_density, **contourpy_kwargs
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
levels = 9
|
|
177
|
-
if "levels" in contourf_kwargs:
|
|
178
|
-
levels = contourf_kwargs.pop("levels")
|
|
179
|
-
if "levels" in contour_kwargs:
|
|
180
|
-
levels = contour_kwargs.pop("levels")
|
|
181
|
-
|
|
182
|
-
if isinstance(levels, Integral):
|
|
183
|
-
levels_scaled = np.linspace(0, 1, levels + 2)
|
|
184
|
-
levels = _rescale_axis(levels_scaled, scaled_density_args)
|
|
185
|
-
else:
|
|
186
|
-
levels_scaled_nonclip, *_ = _scale_axis(np.asarray(levels), scaled_density_args)
|
|
187
|
-
levels_scaled = np.clip(levels_scaled_nonclip, 0, 1)
|
|
188
|
-
|
|
189
|
-
cmap = contourf_kwargs.pop("cmap", "viridis")
|
|
190
|
-
if isinstance(cmap, str):
|
|
191
|
-
cmap = colormaps[cmap]
|
|
192
|
-
if isinstance(cmap, Callable):
|
|
193
|
-
colors = [rgb2hex(item) for item in cmap(np.linspace(0, 1, len(levels_scaled) + 1))]
|
|
194
|
-
else:
|
|
195
|
-
colors = cmap
|
|
196
|
-
|
|
197
|
-
contour_kwargs.update(contourf_kwargs)
|
|
198
|
-
contour_kwargs.setdefault("line_alpha", 0.25)
|
|
199
|
-
contour_kwargs.setdefault("fill_alpha", 1)
|
|
200
|
-
|
|
201
|
-
for i, (level, level_upper, color) in enumerate(
|
|
202
|
-
zip(levels_scaled[:-1], levels_scaled[1:], colors[1:])
|
|
203
|
-
):
|
|
204
|
-
if not fill_last and (i == 0):
|
|
205
|
-
continue
|
|
206
|
-
contour_kwargs_ = contour_kwargs.copy()
|
|
207
|
-
contour_kwargs_.setdefault("line_color", color)
|
|
208
|
-
contour_kwargs_.setdefault("fill_color", color)
|
|
209
|
-
vertices, _ = contour_generator.filled(level, level_upper)
|
|
210
|
-
for seg in vertices:
|
|
211
|
-
# ax.multi_polygon would be better, but input is
|
|
212
|
-
# currently not suitable
|
|
213
|
-
# seg is 1 line that defines an area
|
|
214
|
-
# multi_polygon would need inner and outer edges
|
|
215
|
-
# as a line
|
|
216
|
-
patch = ax.patch(*seg.T, **contour_kwargs_)
|
|
217
|
-
glyphs.append(patch)
|
|
218
|
-
|
|
219
|
-
if fill_last:
|
|
220
|
-
ax.background_fill_color = colors[0]
|
|
221
|
-
|
|
222
|
-
ax.xgrid.grid_line_color = None
|
|
223
|
-
ax.ygrid.grid_line_color = None
|
|
224
|
-
|
|
225
|
-
else:
|
|
226
|
-
cmap = pcolormesh_kwargs.pop("cmap", "viridis")
|
|
227
|
-
if isinstance(cmap, str):
|
|
228
|
-
cmap = colormaps[cmap]
|
|
229
|
-
if isinstance(cmap, Callable):
|
|
230
|
-
colors = [rgb2hex(item) for item in cmap(np.linspace(0, 1, 256))]
|
|
231
|
-
else:
|
|
232
|
-
colors = cmap
|
|
233
|
-
|
|
234
|
-
image = ax.image(
|
|
235
|
-
image=[density.T],
|
|
236
|
-
x=xmin,
|
|
237
|
-
y=ymin,
|
|
238
|
-
dw=(xmax - xmin) / density.shape[0],
|
|
239
|
-
dh=(ymax - ymin) / density.shape[1],
|
|
240
|
-
palette=colors,
|
|
241
|
-
**pcolormesh_kwargs
|
|
242
|
-
)
|
|
243
|
-
glyphs.append(image)
|
|
244
|
-
ax.x_range.range_padding = ax.y_range.range_padding = 0
|
|
245
|
-
|
|
246
|
-
show_layout(ax, show)
|
|
247
|
-
|
|
248
|
-
if return_glyph:
|
|
249
|
-
return ax, glyphs
|
|
250
|
-
|
|
251
|
-
return ax
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
def _scale_axis(arr, args=None):
|
|
255
|
-
if args:
|
|
256
|
-
amin, amax = args
|
|
257
|
-
else:
|
|
258
|
-
amin, amax = arr.min(), arr.max()
|
|
259
|
-
scaled_arr = arr - amin
|
|
260
|
-
scaled_arr /= amax - amin
|
|
261
|
-
return scaled_arr, amin, amax
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
def _rescale_axis(arr, args):
|
|
265
|
-
amin, amax = args
|
|
266
|
-
rescaled_arr = arr * (amax - amin)
|
|
267
|
-
rescaled_arr += amin
|
|
268
|
-
return rescaled_arr
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"""Bokeh pareto shape plot."""
|
|
2
|
-
|
|
3
|
-
from collections.abc import Iterable
|
|
4
|
-
|
|
5
|
-
from matplotlib import cm
|
|
6
|
-
import matplotlib.pyplot as plt
|
|
7
|
-
import numpy as np
|
|
8
|
-
from bokeh.models import Span
|
|
9
|
-
from matplotlib.colors import to_rgba_array
|
|
10
|
-
|
|
11
|
-
from ....stats.density_utils import histogram
|
|
12
|
-
from ...plot_utils import _scale_fig_size, color_from_dim, vectorized_to_hex
|
|
13
|
-
from .. import show_layout
|
|
14
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def plot_khat(
|
|
18
|
-
hover_label, # pylint: disable=unused-argument
|
|
19
|
-
hover_format, # pylint: disable=unused-argument
|
|
20
|
-
ax,
|
|
21
|
-
figsize,
|
|
22
|
-
xdata,
|
|
23
|
-
khats,
|
|
24
|
-
good_k,
|
|
25
|
-
kwargs,
|
|
26
|
-
threshold,
|
|
27
|
-
coord_labels,
|
|
28
|
-
show_hlines,
|
|
29
|
-
show_bins,
|
|
30
|
-
hlines_kwargs,
|
|
31
|
-
xlabels, # pylint: disable=unused-argument
|
|
32
|
-
legend, # pylint: disable=unused-argument
|
|
33
|
-
color,
|
|
34
|
-
dims,
|
|
35
|
-
textsize,
|
|
36
|
-
markersize, # pylint: disable=unused-argument
|
|
37
|
-
n_data_points,
|
|
38
|
-
bin_format,
|
|
39
|
-
backend_kwargs,
|
|
40
|
-
show,
|
|
41
|
-
):
|
|
42
|
-
"""Bokeh khat plot."""
|
|
43
|
-
if backend_kwargs is None:
|
|
44
|
-
backend_kwargs = {}
|
|
45
|
-
|
|
46
|
-
backend_kwargs = {
|
|
47
|
-
**backend_kwarg_defaults(
|
|
48
|
-
("dpi", "plot.bokeh.figure.dpi"),
|
|
49
|
-
),
|
|
50
|
-
**backend_kwargs,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
(figsize, *_, line_width, _) = _scale_fig_size(figsize, textsize)
|
|
54
|
-
|
|
55
|
-
if hlines_kwargs is None:
|
|
56
|
-
hlines_kwargs = {}
|
|
57
|
-
|
|
58
|
-
if good_k is None:
|
|
59
|
-
good_k = 0.7
|
|
60
|
-
|
|
61
|
-
hlines_kwargs.setdefault("hlines", [0, good_k, 1])
|
|
62
|
-
|
|
63
|
-
cmap = None
|
|
64
|
-
if isinstance(color, str):
|
|
65
|
-
if color in dims:
|
|
66
|
-
colors, _ = color_from_dim(khats, color)
|
|
67
|
-
cmap_name = kwargs.get("cmap", plt.rcParams["image.cmap"])
|
|
68
|
-
cmap = getattr(cm, cmap_name)
|
|
69
|
-
rgba_c = cmap(colors)
|
|
70
|
-
else:
|
|
71
|
-
legend = False
|
|
72
|
-
rgba_c = to_rgba_array(np.full(n_data_points, color))
|
|
73
|
-
else:
|
|
74
|
-
legend = False
|
|
75
|
-
try:
|
|
76
|
-
rgba_c = to_rgba_array(color)
|
|
77
|
-
except ValueError:
|
|
78
|
-
cmap_name = kwargs.get("cmap", plt.rcParams["image.cmap"])
|
|
79
|
-
cmap = getattr(cm, cmap_name)
|
|
80
|
-
rgba_c = cmap(color)
|
|
81
|
-
|
|
82
|
-
khats = khats if isinstance(khats, np.ndarray) else khats.values.flatten()
|
|
83
|
-
alphas = 0.5 + 0.2 * (khats > good_k) + 0.3 * (khats > 1)
|
|
84
|
-
|
|
85
|
-
rgba_c = vectorized_to_hex(rgba_c)
|
|
86
|
-
|
|
87
|
-
if ax is None:
|
|
88
|
-
ax = create_axes_grid(
|
|
89
|
-
1,
|
|
90
|
-
figsize=figsize,
|
|
91
|
-
squeeze=True,
|
|
92
|
-
backend_kwargs=backend_kwargs,
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
if not isinstance(rgba_c, str) and isinstance(rgba_c, Iterable):
|
|
96
|
-
for idx, (alpha, rgba_c_) in enumerate(zip(alphas, rgba_c)):
|
|
97
|
-
ax.scatter(
|
|
98
|
-
xdata[idx],
|
|
99
|
-
khats[idx],
|
|
100
|
-
marker="cross",
|
|
101
|
-
line_color=rgba_c_,
|
|
102
|
-
fill_color=rgba_c_,
|
|
103
|
-
line_alpha=alpha,
|
|
104
|
-
fill_alpha=alpha,
|
|
105
|
-
size=10,
|
|
106
|
-
)
|
|
107
|
-
else:
|
|
108
|
-
ax.scatter(
|
|
109
|
-
xdata,
|
|
110
|
-
khats,
|
|
111
|
-
marker="cross",
|
|
112
|
-
line_color=rgba_c,
|
|
113
|
-
fill_color=rgba_c,
|
|
114
|
-
size=10,
|
|
115
|
-
line_alpha=alphas,
|
|
116
|
-
fill_alpha=alphas,
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
if threshold is not None:
|
|
120
|
-
idxs = xdata[khats > threshold]
|
|
121
|
-
for idx in idxs:
|
|
122
|
-
ax.text(x=[idx], y=[khats[idx]], text=[coord_labels[idx]])
|
|
123
|
-
|
|
124
|
-
if show_hlines:
|
|
125
|
-
for hline in hlines_kwargs.pop("hlines"):
|
|
126
|
-
_hline = Span(
|
|
127
|
-
location=hline,
|
|
128
|
-
dimension="width",
|
|
129
|
-
line_color="grey",
|
|
130
|
-
line_width=line_width,
|
|
131
|
-
line_dash="dashed",
|
|
132
|
-
)
|
|
133
|
-
ax.renderers.append(_hline)
|
|
134
|
-
|
|
135
|
-
ymin = min(khats)
|
|
136
|
-
ymax = max(khats)
|
|
137
|
-
xmax = len(khats)
|
|
138
|
-
|
|
139
|
-
if show_bins:
|
|
140
|
-
bin_edges = np.array([ymin, good_k, 1, ymax])
|
|
141
|
-
bin_edges = bin_edges[(bin_edges >= ymin) & (bin_edges <= ymax)]
|
|
142
|
-
hist, _, _ = histogram(khats, bin_edges)
|
|
143
|
-
for idx, count in enumerate(hist):
|
|
144
|
-
ax.text(
|
|
145
|
-
x=[(n_data_points - 1 + xmax) / 2],
|
|
146
|
-
y=[np.mean(bin_edges[idx : idx + 2])],
|
|
147
|
-
text=[bin_format.format(count, count / n_data_points * 100)],
|
|
148
|
-
)
|
|
149
|
-
ax.x_range._property_values["end"] = xmax + 1 # pylint: disable=protected-access
|
|
150
|
-
|
|
151
|
-
ax.xaxis.axis_label = "Data Point"
|
|
152
|
-
ax.yaxis.axis_label = "Shape parameter k"
|
|
153
|
-
|
|
154
|
-
if ymin > 0:
|
|
155
|
-
ax.y_range._property_values["start"] = -0.02 # pylint: disable=protected-access
|
|
156
|
-
if ymax < 1:
|
|
157
|
-
ax.y_range._property_values["end"] = 1.02 # pylint: disable=protected-access
|
|
158
|
-
elif ymax > 1 & threshold:
|
|
159
|
-
ax.y_range._property_values["end"] = 1.1 * ymax # pylint: disable=protected-access
|
|
160
|
-
|
|
161
|
-
show_layout(ax, show)
|
|
162
|
-
|
|
163
|
-
return ax
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"""Bokeh linear regression plot."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
from bokeh.models.annotations import Legend
|
|
5
|
-
|
|
6
|
-
from ...hdiplot import plot_hdi
|
|
7
|
-
|
|
8
|
-
from ...plot_utils import _scale_fig_size
|
|
9
|
-
from .. import show_layout
|
|
10
|
-
from . import backend_kwarg_defaults, create_axes_grid
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def plot_lm(
|
|
14
|
-
x,
|
|
15
|
-
y,
|
|
16
|
-
y_model,
|
|
17
|
-
y_hat,
|
|
18
|
-
num_samples,
|
|
19
|
-
kind_pp,
|
|
20
|
-
kind_model,
|
|
21
|
-
length_plotters,
|
|
22
|
-
xjitter,
|
|
23
|
-
rows,
|
|
24
|
-
cols,
|
|
25
|
-
y_kwargs,
|
|
26
|
-
y_hat_plot_kwargs,
|
|
27
|
-
y_hat_fill_kwargs,
|
|
28
|
-
y_model_plot_kwargs,
|
|
29
|
-
y_model_fill_kwargs,
|
|
30
|
-
y_model_mean_kwargs,
|
|
31
|
-
backend_kwargs,
|
|
32
|
-
show,
|
|
33
|
-
figsize,
|
|
34
|
-
textsize,
|
|
35
|
-
axes,
|
|
36
|
-
legend,
|
|
37
|
-
grid, # pylint: disable=unused-argument
|
|
38
|
-
):
|
|
39
|
-
"""Bokeh linreg plot."""
|
|
40
|
-
if backend_kwargs is None:
|
|
41
|
-
backend_kwargs = {}
|
|
42
|
-
|
|
43
|
-
backend_kwargs = {
|
|
44
|
-
**backend_kwarg_defaults(),
|
|
45
|
-
**backend_kwargs,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
figsize, *_ = _scale_fig_size(figsize, textsize, rows, cols)
|
|
49
|
-
if axes is None:
|
|
50
|
-
axes = create_axes_grid(length_plotters, rows, cols, backend_kwargs=backend_kwargs)
|
|
51
|
-
|
|
52
|
-
if y_kwargs is None:
|
|
53
|
-
y_kwargs = {}
|
|
54
|
-
else:
|
|
55
|
-
y_kwargs = y_kwargs.copy()
|
|
56
|
-
y_kwargs.setdefault("marker", "circle")
|
|
57
|
-
y_kwargs.setdefault("fill_color", "red")
|
|
58
|
-
y_kwargs.setdefault("line_width", 0)
|
|
59
|
-
y_kwargs.setdefault("size", 3)
|
|
60
|
-
|
|
61
|
-
if y_hat_plot_kwargs is None:
|
|
62
|
-
y_hat_plot_kwargs = {}
|
|
63
|
-
else:
|
|
64
|
-
y_hat_plot_kwargs = y_hat_plot_kwargs.copy()
|
|
65
|
-
y_hat_plot_kwargs.setdefault("marker", "circle")
|
|
66
|
-
y_hat_plot_kwargs.setdefault("fill_color", "orange")
|
|
67
|
-
y_hat_plot_kwargs.setdefault("line_width", 0)
|
|
68
|
-
|
|
69
|
-
if y_hat_fill_kwargs is None:
|
|
70
|
-
y_hat_fill_kwargs = {}
|
|
71
|
-
else:
|
|
72
|
-
y_hat_fill_kwargs = y_hat_fill_kwargs.copy()
|
|
73
|
-
# Convert matplotlib color to bokeh fill_color if needed
|
|
74
|
-
if "color" in y_hat_fill_kwargs and "fill_color" not in y_hat_fill_kwargs:
|
|
75
|
-
y_hat_fill_kwargs["fill_color"] = y_hat_fill_kwargs.pop("color")
|
|
76
|
-
y_hat_fill_kwargs.setdefault("fill_color", "orange")
|
|
77
|
-
y_hat_fill_kwargs.setdefault("fill_alpha", 0.5)
|
|
78
|
-
|
|
79
|
-
if y_model_plot_kwargs is None:
|
|
80
|
-
y_model_plot_kwargs = {}
|
|
81
|
-
y_model_plot_kwargs.setdefault("line_color", "black")
|
|
82
|
-
y_model_plot_kwargs.setdefault("line_alpha", 0.5)
|
|
83
|
-
y_model_plot_kwargs.setdefault("line_width", 0.5)
|
|
84
|
-
|
|
85
|
-
if y_model_fill_kwargs is None:
|
|
86
|
-
y_model_fill_kwargs = {}
|
|
87
|
-
else:
|
|
88
|
-
y_model_fill_kwargs = y_model_fill_kwargs.copy()
|
|
89
|
-
# Convert matplotlib color to bokeh fill_color if needed
|
|
90
|
-
if "color" in y_model_fill_kwargs and "fill_color" not in y_model_fill_kwargs:
|
|
91
|
-
y_model_fill_kwargs["fill_color"] = y_model_fill_kwargs.pop("color")
|
|
92
|
-
y_model_fill_kwargs.setdefault("fill_color", "black")
|
|
93
|
-
y_model_fill_kwargs.setdefault("fill_alpha", 0.5)
|
|
94
|
-
|
|
95
|
-
if y_model_mean_kwargs is None:
|
|
96
|
-
y_model_mean_kwargs = {}
|
|
97
|
-
y_model_mean_kwargs.setdefault("line_color", "yellow")
|
|
98
|
-
y_model_mean_kwargs.setdefault("line_width", 2)
|
|
99
|
-
|
|
100
|
-
for i, ax_i in enumerate((item for item in axes.flatten() if item is not None)):
|
|
101
|
-
_, _, _, y_plotters = y[i]
|
|
102
|
-
_, _, _, x_plotters = x[i]
|
|
103
|
-
legend_it = []
|
|
104
|
-
observed_legend = ax_i.scatter(x_plotters, y_plotters, **y_kwargs)
|
|
105
|
-
legend_it.append(("Observed", [observed_legend]))
|
|
106
|
-
|
|
107
|
-
if y_hat is not None:
|
|
108
|
-
_, _, _, y_hat_plotters = y_hat[i]
|
|
109
|
-
if kind_pp == "samples":
|
|
110
|
-
posterior_legend = []
|
|
111
|
-
for j in range(num_samples):
|
|
112
|
-
if xjitter is True:
|
|
113
|
-
jitter_scale = x_plotters[1] - x_plotters[0]
|
|
114
|
-
scale_high = jitter_scale * 0.2
|
|
115
|
-
x_plotters_jitter = x_plotters + np.random.uniform(
|
|
116
|
-
low=-scale_high, high=scale_high, size=len(x_plotters)
|
|
117
|
-
)
|
|
118
|
-
posterior_circle = ax_i.scatter(
|
|
119
|
-
x_plotters_jitter,
|
|
120
|
-
y_hat_plotters[..., j],
|
|
121
|
-
alpha=0.2,
|
|
122
|
-
**y_hat_plot_kwargs,
|
|
123
|
-
)
|
|
124
|
-
else:
|
|
125
|
-
posterior_circle = ax_i.scatter(
|
|
126
|
-
x_plotters, y_hat_plotters[..., j], alpha=0.2, **y_hat_plot_kwargs
|
|
127
|
-
)
|
|
128
|
-
posterior_legend.append(posterior_circle)
|
|
129
|
-
legend_it.append(("Posterior predictive samples", posterior_legend))
|
|
130
|
-
|
|
131
|
-
else:
|
|
132
|
-
plot_hdi(
|
|
133
|
-
x_plotters,
|
|
134
|
-
y_hat_plotters,
|
|
135
|
-
ax=ax_i,
|
|
136
|
-
backend="bokeh",
|
|
137
|
-
fill_kwargs=y_hat_fill_kwargs,
|
|
138
|
-
show=False,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
if y_model is not None:
|
|
142
|
-
_, _, _, y_model_plotters = y_model[i]
|
|
143
|
-
if kind_model == "lines":
|
|
144
|
-
model_legend = ax_i.multi_line(
|
|
145
|
-
[np.tile(np.array(x_plotters, dtype=object), (num_samples, 1))],
|
|
146
|
-
[np.transpose(y_model_plotters)],
|
|
147
|
-
**y_model_plot_kwargs,
|
|
148
|
-
)
|
|
149
|
-
legend_it.append(("Uncertainty in mean", [model_legend]))
|
|
150
|
-
|
|
151
|
-
y_model_mean = np.mean(y_model_plotters, axis=1)
|
|
152
|
-
else:
|
|
153
|
-
plot_hdi(
|
|
154
|
-
x_plotters,
|
|
155
|
-
y_model_plotters,
|
|
156
|
-
fill_kwargs=y_model_fill_kwargs,
|
|
157
|
-
ax=ax_i,
|
|
158
|
-
backend="bokeh",
|
|
159
|
-
show=False,
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
y_model_mean = np.mean(y_model_plotters, axis=(0, 1))
|
|
163
|
-
# Plot mean line across all x values instead of just edges
|
|
164
|
-
mean_legend = ax_i.line(x_plotters, y_model_mean, **y_model_mean_kwargs)
|
|
165
|
-
legend_it.append(("Mean", [mean_legend]))
|
|
166
|
-
continue # Skip the edge plotting since we plotted full line
|
|
167
|
-
|
|
168
|
-
x_plotters_edge = [min(x_plotters), max(x_plotters)]
|
|
169
|
-
y_model_mean_edge = [min(y_model_mean), max(y_model_mean)]
|
|
170
|
-
mean_legend = ax_i.line(x_plotters_edge, y_model_mean_edge, **y_model_mean_kwargs)
|
|
171
|
-
legend_it.append(("Mean", [mean_legend]))
|
|
172
|
-
|
|
173
|
-
if legend:
|
|
174
|
-
legend = Legend(
|
|
175
|
-
items=legend_it,
|
|
176
|
-
location="top_left",
|
|
177
|
-
orientation="vertical",
|
|
178
|
-
)
|
|
179
|
-
ax_i.add_layout(legend)
|
|
180
|
-
if textsize is not None:
|
|
181
|
-
ax_i.legend.label_text_font_size = f"{textsize}pt"
|
|
182
|
-
ax_i.legend.click_policy = "hide"
|
|
183
|
-
|
|
184
|
-
show_layout(axes, show)
|
|
185
|
-
return axes
|