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,177 +0,0 @@
|
|
|
1
|
-
"""Matplotlib kdeplot."""
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
from matplotlib import pyplot as plt
|
|
5
|
-
from matplotlib import _pylab_helpers
|
|
6
|
-
import matplotlib.ticker as mticker
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from ...plot_utils import _scale_fig_size, _init_kwargs_dict
|
|
10
|
-
from . import backend_kwarg_defaults, backend_show, create_axes_grid, matplotlib_kwarg_dealiaser
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def plot_kde(
|
|
14
|
-
density,
|
|
15
|
-
lower,
|
|
16
|
-
upper,
|
|
17
|
-
density_q,
|
|
18
|
-
xmin,
|
|
19
|
-
xmax,
|
|
20
|
-
ymin,
|
|
21
|
-
ymax,
|
|
22
|
-
gridsize,
|
|
23
|
-
values,
|
|
24
|
-
values2,
|
|
25
|
-
rug,
|
|
26
|
-
label,
|
|
27
|
-
quantiles,
|
|
28
|
-
rotated,
|
|
29
|
-
contour,
|
|
30
|
-
fill_last,
|
|
31
|
-
figsize,
|
|
32
|
-
textsize,
|
|
33
|
-
plot_kwargs,
|
|
34
|
-
fill_kwargs,
|
|
35
|
-
rug_kwargs,
|
|
36
|
-
contour_kwargs,
|
|
37
|
-
contourf_kwargs,
|
|
38
|
-
pcolormesh_kwargs,
|
|
39
|
-
is_circular,
|
|
40
|
-
ax,
|
|
41
|
-
legend,
|
|
42
|
-
backend_kwargs,
|
|
43
|
-
show,
|
|
44
|
-
return_glyph, # pylint: disable=unused-argument
|
|
45
|
-
):
|
|
46
|
-
"""Matplotlib kde plot."""
|
|
47
|
-
backend_kwargs = _init_kwargs_dict(backend_kwargs)
|
|
48
|
-
|
|
49
|
-
backend_kwargs = {
|
|
50
|
-
**backend_kwarg_defaults(),
|
|
51
|
-
**backend_kwargs,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
figsize, *_, xt_labelsize, linewidth, markersize = _scale_fig_size(figsize, textsize)
|
|
55
|
-
|
|
56
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
57
|
-
backend_kwargs["squeeze"] = True
|
|
58
|
-
backend_kwargs.setdefault("subplot_kw", {})
|
|
59
|
-
backend_kwargs["subplot_kw"].setdefault("polar", is_circular)
|
|
60
|
-
|
|
61
|
-
if ax is None:
|
|
62
|
-
fig_manager = _pylab_helpers.Gcf.get_active()
|
|
63
|
-
if fig_manager is not None:
|
|
64
|
-
ax = fig_manager.canvas.figure.gca()
|
|
65
|
-
else:
|
|
66
|
-
_, ax = create_axes_grid(
|
|
67
|
-
1,
|
|
68
|
-
backend_kwargs=backend_kwargs,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
if values2 is None:
|
|
72
|
-
plot_kwargs = matplotlib_kwarg_dealiaser(plot_kwargs, "plot")
|
|
73
|
-
plot_kwargs.setdefault("color", "C0")
|
|
74
|
-
|
|
75
|
-
default_color = plot_kwargs.get("color")
|
|
76
|
-
|
|
77
|
-
fill_kwargs = matplotlib_kwarg_dealiaser(fill_kwargs, "hexbin")
|
|
78
|
-
fill_kwargs.setdefault("color", default_color)
|
|
79
|
-
|
|
80
|
-
rug_kwargs = matplotlib_kwarg_dealiaser(rug_kwargs, "plot")
|
|
81
|
-
rug_kwargs.setdefault("marker", "_" if rotated else "|")
|
|
82
|
-
rug_kwargs.setdefault("linestyle", "None")
|
|
83
|
-
rug_kwargs.setdefault("color", default_color)
|
|
84
|
-
rug_kwargs.setdefault("space", 0.2)
|
|
85
|
-
|
|
86
|
-
plot_kwargs.setdefault("linewidth", linewidth)
|
|
87
|
-
rug_kwargs.setdefault("markersize", 2 * markersize)
|
|
88
|
-
|
|
89
|
-
rug_space = max(density) * rug_kwargs.pop("space")
|
|
90
|
-
|
|
91
|
-
if is_circular:
|
|
92
|
-
if is_circular == "radians":
|
|
93
|
-
labels = [
|
|
94
|
-
"0",
|
|
95
|
-
f"{np.pi/4:.2f}",
|
|
96
|
-
f"{np.pi/2:.2f}",
|
|
97
|
-
f"{3*np.pi/4:.2f}",
|
|
98
|
-
f"{np.pi:.2f}",
|
|
99
|
-
f"{-3*np.pi/4:.2f}",
|
|
100
|
-
f"{-np.pi/2:.2f}",
|
|
101
|
-
f"{-np.pi/4:.2f}",
|
|
102
|
-
]
|
|
103
|
-
|
|
104
|
-
ticks_loc = ax.get_xticks()
|
|
105
|
-
ax.xaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
|
|
106
|
-
ax.set_xticklabels(labels)
|
|
107
|
-
|
|
108
|
-
x = np.linspace(-np.pi, np.pi, len(density))
|
|
109
|
-
ax.set_yticklabels([])
|
|
110
|
-
|
|
111
|
-
else:
|
|
112
|
-
x = np.linspace(lower, upper, len(density))
|
|
113
|
-
|
|
114
|
-
fill_func = ax.fill_between
|
|
115
|
-
fill_x, fill_y = x, density
|
|
116
|
-
if rotated:
|
|
117
|
-
x, density = density, x
|
|
118
|
-
fill_func = ax.fill_betweenx
|
|
119
|
-
|
|
120
|
-
ax.tick_params(labelsize=xt_labelsize)
|
|
121
|
-
|
|
122
|
-
if rotated:
|
|
123
|
-
ax.set_xlim(0, auto=True)
|
|
124
|
-
rug_x, rug_y = np.zeros_like(values) - rug_space, values
|
|
125
|
-
else:
|
|
126
|
-
ax.set_ylim(0, auto=True)
|
|
127
|
-
rug_x, rug_y = values, np.zeros_like(values) - rug_space
|
|
128
|
-
|
|
129
|
-
if rug:
|
|
130
|
-
ax.plot(rug_x, rug_y, **rug_kwargs)
|
|
131
|
-
|
|
132
|
-
if quantiles is not None:
|
|
133
|
-
fill_kwargs.setdefault("alpha", 0.75)
|
|
134
|
-
|
|
135
|
-
idx = [np.sum(density_q < quant) for quant in quantiles]
|
|
136
|
-
|
|
137
|
-
fill_func(
|
|
138
|
-
fill_x,
|
|
139
|
-
fill_y,
|
|
140
|
-
where=np.isin(fill_x, fill_x[idx], invert=True, assume_unique=True),
|
|
141
|
-
**fill_kwargs,
|
|
142
|
-
)
|
|
143
|
-
else:
|
|
144
|
-
fill_kwargs.setdefault("alpha", 0)
|
|
145
|
-
if fill_kwargs.get("alpha") == 0:
|
|
146
|
-
label = plot_kwargs.setdefault("label", label)
|
|
147
|
-
else:
|
|
148
|
-
label = fill_kwargs.setdefault("label", label)
|
|
149
|
-
ax.plot(x, density, **plot_kwargs)
|
|
150
|
-
fill_func(fill_x, fill_y, **fill_kwargs)
|
|
151
|
-
if legend and label:
|
|
152
|
-
ax.legend()
|
|
153
|
-
else:
|
|
154
|
-
contour_kwargs = matplotlib_kwarg_dealiaser(contour_kwargs, "contour")
|
|
155
|
-
contour_kwargs.setdefault("colors", "0.5")
|
|
156
|
-
contourf_kwargs = matplotlib_kwarg_dealiaser(contourf_kwargs, "contour")
|
|
157
|
-
pcolormesh_kwargs = matplotlib_kwarg_dealiaser(pcolormesh_kwargs, "pcolormesh")
|
|
158
|
-
pcolormesh_kwargs.setdefault("shading", "auto")
|
|
159
|
-
|
|
160
|
-
g_s = complex(gridsize[0])
|
|
161
|
-
x_x, y_y = np.mgrid[xmin:xmax:g_s, ymin:ymax:g_s]
|
|
162
|
-
|
|
163
|
-
ax.grid(False)
|
|
164
|
-
if contour:
|
|
165
|
-
qcfs = ax.contourf(x_x, y_y, density, antialiased=True, **contourf_kwargs)
|
|
166
|
-
ax.contour(x_x, y_y, density, **contour_kwargs)
|
|
167
|
-
if not fill_last:
|
|
168
|
-
alpha = np.ones(len(qcfs.allsegs), dtype=float)
|
|
169
|
-
alpha[0] = 0
|
|
170
|
-
qcfs.set_alpha(alpha)
|
|
171
|
-
else:
|
|
172
|
-
ax.pcolormesh(x_x, y_y, density, **pcolormesh_kwargs)
|
|
173
|
-
|
|
174
|
-
if backend_show(show):
|
|
175
|
-
plt.show()
|
|
176
|
-
|
|
177
|
-
return ax
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"""Matplotlib khatplot."""
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
|
|
5
|
-
import matplotlib as mpl
|
|
6
|
-
from matplotlib import cm
|
|
7
|
-
import matplotlib.pyplot as plt
|
|
8
|
-
import numpy as np
|
|
9
|
-
from matplotlib.colors import to_rgba_array
|
|
10
|
-
from packaging import version
|
|
11
|
-
|
|
12
|
-
from ....stats.density_utils import histogram
|
|
13
|
-
from ...plot_utils import _scale_fig_size, color_from_dim, set_xticklabels, vectorized_to_hex
|
|
14
|
-
from . import backend_show, create_axes_grid, matplotlib_kwarg_dealiaser
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def plot_khat(
|
|
18
|
-
hover_label,
|
|
19
|
-
hover_format,
|
|
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,
|
|
32
|
-
legend,
|
|
33
|
-
color,
|
|
34
|
-
dims,
|
|
35
|
-
textsize,
|
|
36
|
-
markersize,
|
|
37
|
-
n_data_points,
|
|
38
|
-
bin_format,
|
|
39
|
-
backend_kwargs,
|
|
40
|
-
show,
|
|
41
|
-
):
|
|
42
|
-
"""Matplotlib khat plot."""
|
|
43
|
-
if version.parse(mpl.__version__) >= version.parse("3.9.0.dev0"):
|
|
44
|
-
interactive_backends = mpl.backends.backend_registry.list_builtin(
|
|
45
|
-
mpl.backends.BackendFilter.INTERACTIVE
|
|
46
|
-
)
|
|
47
|
-
else:
|
|
48
|
-
interactive_backends = mpl.rcsetup.interactive_bk
|
|
49
|
-
if hover_label and mpl.get_backend() not in interactive_backends:
|
|
50
|
-
hover_label = False
|
|
51
|
-
warnings.warn(
|
|
52
|
-
"hover labels are only available with interactive backends. To switch to an "
|
|
53
|
-
"interactive backend from ipython or jupyter, use `%matplotlib` there should be "
|
|
54
|
-
"no need to restart the kernel. For other cases, see "
|
|
55
|
-
"https://matplotlib.org/3.1.0/tutorials/introductory/usage.html#backends",
|
|
56
|
-
UserWarning,
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
if backend_kwargs is None:
|
|
60
|
-
backend_kwargs = {}
|
|
61
|
-
|
|
62
|
-
backend_kwargs = {
|
|
63
|
-
**backend_kwargs,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
(figsize, ax_labelsize, _, xt_labelsize, linewidth, scaled_markersize) = _scale_fig_size(
|
|
67
|
-
figsize, textsize
|
|
68
|
-
)
|
|
69
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
70
|
-
backend_kwargs["squeeze"] = True
|
|
71
|
-
|
|
72
|
-
if good_k is None:
|
|
73
|
-
good_k = 0.7
|
|
74
|
-
|
|
75
|
-
hlines_kwargs = matplotlib_kwarg_dealiaser(hlines_kwargs, "hlines")
|
|
76
|
-
hlines_kwargs.setdefault("hlines", [0, good_k, 1])
|
|
77
|
-
hlines_kwargs.setdefault("linestyle", [":", "-.", "--", "-"])
|
|
78
|
-
hlines_kwargs.setdefault("alpha", 0.7)
|
|
79
|
-
hlines_kwargs.setdefault("zorder", -1)
|
|
80
|
-
hlines_kwargs.setdefault("color", "C1")
|
|
81
|
-
hlines_kwargs["color"] = vectorized_to_hex(hlines_kwargs["color"])
|
|
82
|
-
|
|
83
|
-
if markersize is None:
|
|
84
|
-
markersize = scaled_markersize**2 # s in scatter plot mus be markersize square
|
|
85
|
-
# for dots to have the same size
|
|
86
|
-
|
|
87
|
-
kwargs = matplotlib_kwarg_dealiaser(kwargs, "scatter")
|
|
88
|
-
kwargs.setdefault("s", markersize)
|
|
89
|
-
kwargs.setdefault("marker", "+")
|
|
90
|
-
|
|
91
|
-
c_kwarg = kwargs.get("c", None)
|
|
92
|
-
|
|
93
|
-
if c_kwarg is None:
|
|
94
|
-
color_mapping = None
|
|
95
|
-
cmap = None
|
|
96
|
-
if isinstance(color, str):
|
|
97
|
-
if color in dims:
|
|
98
|
-
colors, color_mapping = color_from_dim(khats, color)
|
|
99
|
-
cmap_name = kwargs.get("cmap", plt.rcParams["image.cmap"])
|
|
100
|
-
cmap = getattr(cm, cmap_name)
|
|
101
|
-
rgba_c = cmap(colors)
|
|
102
|
-
else:
|
|
103
|
-
legend = False
|
|
104
|
-
rgba_c = to_rgba_array(np.full(n_data_points, color))
|
|
105
|
-
else:
|
|
106
|
-
legend = False
|
|
107
|
-
try:
|
|
108
|
-
rgba_c = to_rgba_array(color)
|
|
109
|
-
except ValueError:
|
|
110
|
-
cmap_name = kwargs.get("cmap", plt.rcParams["image.cmap"])
|
|
111
|
-
cmap = getattr(cm, cmap_name)
|
|
112
|
-
norm_fun = kwargs.get("norm", mpl.colors.Normalize(color.min(), color.max()))
|
|
113
|
-
rgba_c = cmap(norm_fun(color))
|
|
114
|
-
|
|
115
|
-
khats = khats if isinstance(khats, np.ndarray) else khats.values.flatten()
|
|
116
|
-
alphas = 0.5 + 0.2 * (khats > good_k) + 0.3 * (khats > 1)
|
|
117
|
-
rgba_c[:, 3] = alphas
|
|
118
|
-
rgba_c = vectorized_to_hex(rgba_c)
|
|
119
|
-
kwargs["c"] = rgba_c
|
|
120
|
-
else:
|
|
121
|
-
if isinstance(c_kwarg, str):
|
|
122
|
-
if c_kwarg in dims:
|
|
123
|
-
colors, color_mapping = color_from_dim(khats, c_kwarg)
|
|
124
|
-
else:
|
|
125
|
-
legend = False
|
|
126
|
-
else:
|
|
127
|
-
legend = False
|
|
128
|
-
|
|
129
|
-
if ax is None:
|
|
130
|
-
fig, ax = create_axes_grid(
|
|
131
|
-
1,
|
|
132
|
-
backend_kwargs=backend_kwargs,
|
|
133
|
-
)
|
|
134
|
-
else:
|
|
135
|
-
fig = ax.get_figure()
|
|
136
|
-
|
|
137
|
-
sc_plot = ax.scatter(xdata, khats, **kwargs)
|
|
138
|
-
|
|
139
|
-
if threshold is not None:
|
|
140
|
-
idxs = xdata[khats > threshold]
|
|
141
|
-
for idx in idxs:
|
|
142
|
-
ax.text(
|
|
143
|
-
idx,
|
|
144
|
-
khats[idx],
|
|
145
|
-
coord_labels[idx],
|
|
146
|
-
horizontalalignment="center",
|
|
147
|
-
verticalalignment="bottom",
|
|
148
|
-
fontsize=0.8 * xt_labelsize,
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
xmin, xmax = ax.get_xlim()
|
|
152
|
-
if show_bins:
|
|
153
|
-
xmax += n_data_points / 12
|
|
154
|
-
ylims1 = ax.get_ylim()
|
|
155
|
-
ylims2 = ax.get_ylim()
|
|
156
|
-
ymin = min(ylims1[0], ylims2[0])
|
|
157
|
-
ymax = min(ylims1[1], ylims2[1])
|
|
158
|
-
|
|
159
|
-
if show_hlines:
|
|
160
|
-
ax.hlines(
|
|
161
|
-
hlines_kwargs.pop("hlines"), xmin=xmin, xmax=xmax, linewidth=linewidth, **hlines_kwargs
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
if show_bins:
|
|
165
|
-
bin_edges = np.array([ymin, good_k, 1, ymax])
|
|
166
|
-
bin_edges = bin_edges[(bin_edges >= ymin) & (bin_edges <= ymax)]
|
|
167
|
-
hist, _, _ = histogram(khats, bin_edges)
|
|
168
|
-
for idx, count in enumerate(hist):
|
|
169
|
-
ax.text(
|
|
170
|
-
(n_data_points - 1 + xmax) / 2,
|
|
171
|
-
np.mean(bin_edges[idx : idx + 2]),
|
|
172
|
-
bin_format.format(count, count / n_data_points * 100),
|
|
173
|
-
horizontalalignment="center",
|
|
174
|
-
verticalalignment="center",
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
ax.set_xlabel("Data Point", fontsize=ax_labelsize)
|
|
178
|
-
ax.set_ylabel(r"Shape parameter k", fontsize=ax_labelsize)
|
|
179
|
-
ax.tick_params(labelsize=xt_labelsize)
|
|
180
|
-
if xlabels:
|
|
181
|
-
set_xticklabels(ax, coord_labels)
|
|
182
|
-
fig.autofmt_xdate()
|
|
183
|
-
fig.tight_layout()
|
|
184
|
-
if legend:
|
|
185
|
-
kwargs.pop("c")
|
|
186
|
-
ncols = len(color_mapping) // 6 + 1
|
|
187
|
-
for label, float_color in color_mapping.items():
|
|
188
|
-
ax.scatter([], [], c=[cmap(float_color)], label=label, **kwargs)
|
|
189
|
-
ax.legend(ncol=ncols, title=color)
|
|
190
|
-
|
|
191
|
-
if hover_label and mpl.get_backend() in mpl.rcsetup.interactive_bk:
|
|
192
|
-
_make_hover_annotation(fig, ax, sc_plot, coord_labels, rgba_c, hover_format)
|
|
193
|
-
|
|
194
|
-
if backend_show(show):
|
|
195
|
-
plt.show()
|
|
196
|
-
|
|
197
|
-
return ax
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def _make_hover_annotation(fig, ax, sc_plot, coord_labels, rgba_c, hover_format):
|
|
201
|
-
"""Show data point label when hovering over it with mouse."""
|
|
202
|
-
annot = ax.annotate(
|
|
203
|
-
"",
|
|
204
|
-
xy=(0, 0),
|
|
205
|
-
xytext=(0, 0),
|
|
206
|
-
textcoords="offset points",
|
|
207
|
-
bbox=dict(boxstyle="round", fc="w", alpha=0.4),
|
|
208
|
-
arrowprops=dict(arrowstyle="->"),
|
|
209
|
-
)
|
|
210
|
-
annot.set_visible(False)
|
|
211
|
-
xmid = np.mean(ax.get_xlim())
|
|
212
|
-
ymid = np.mean(ax.get_ylim())
|
|
213
|
-
offset = 10
|
|
214
|
-
|
|
215
|
-
def update_annot(ind):
|
|
216
|
-
idx = ind["ind"][0]
|
|
217
|
-
pos = sc_plot.get_offsets()[idx]
|
|
218
|
-
annot_text = hover_format.format(idx, coord_labels[idx])
|
|
219
|
-
annot.xy = pos
|
|
220
|
-
annot.set_position(
|
|
221
|
-
(-offset if pos[0] > xmid else offset, -offset if pos[1] > ymid else offset)
|
|
222
|
-
)
|
|
223
|
-
annot.set_text(annot_text)
|
|
224
|
-
annot.get_bbox_patch().set_facecolor(rgba_c[idx])
|
|
225
|
-
annot.set_ha("right" if pos[0] > xmid else "left")
|
|
226
|
-
annot.set_va("top" if pos[1] > ymid else "bottom")
|
|
227
|
-
|
|
228
|
-
def hover(event):
|
|
229
|
-
vis = annot.get_visible()
|
|
230
|
-
if event.inaxes == ax:
|
|
231
|
-
cont, ind = sc_plot.contains(event)
|
|
232
|
-
if cont:
|
|
233
|
-
update_annot(ind)
|
|
234
|
-
annot.set_visible(True)
|
|
235
|
-
fig.canvas.draw_idle()
|
|
236
|
-
else:
|
|
237
|
-
if vis:
|
|
238
|
-
annot.set_visible(False)
|
|
239
|
-
fig.canvas.draw_idle()
|
|
240
|
-
|
|
241
|
-
fig.canvas.mpl_connect("motion_notify_event", hover)
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"""Matplotlib plot linear regression figure."""
|
|
2
|
-
|
|
3
|
-
import matplotlib.pyplot as plt
|
|
4
|
-
import numpy as np
|
|
5
|
-
|
|
6
|
-
from ...plot_utils import _scale_fig_size
|
|
7
|
-
from ...hdiplot import plot_hdi
|
|
8
|
-
from . import create_axes_grid, matplotlib_kwarg_dealiaser, backend_show, backend_kwarg_defaults
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def plot_lm(
|
|
12
|
-
x,
|
|
13
|
-
y,
|
|
14
|
-
y_model,
|
|
15
|
-
y_hat,
|
|
16
|
-
num_samples,
|
|
17
|
-
kind_pp,
|
|
18
|
-
kind_model,
|
|
19
|
-
xjitter,
|
|
20
|
-
length_plotters,
|
|
21
|
-
rows,
|
|
22
|
-
cols,
|
|
23
|
-
y_kwargs,
|
|
24
|
-
y_hat_plot_kwargs,
|
|
25
|
-
y_hat_fill_kwargs,
|
|
26
|
-
y_model_plot_kwargs,
|
|
27
|
-
y_model_fill_kwargs,
|
|
28
|
-
y_model_mean_kwargs,
|
|
29
|
-
backend_kwargs,
|
|
30
|
-
show,
|
|
31
|
-
figsize,
|
|
32
|
-
textsize,
|
|
33
|
-
axes,
|
|
34
|
-
legend,
|
|
35
|
-
grid,
|
|
36
|
-
):
|
|
37
|
-
"""Matplotlib Linear Regression."""
|
|
38
|
-
if backend_kwargs is None:
|
|
39
|
-
backend_kwargs = {}
|
|
40
|
-
|
|
41
|
-
backend_kwargs = {
|
|
42
|
-
**backend_kwarg_defaults(),
|
|
43
|
-
**backend_kwargs,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
figsize, _, _, xt_labelsize, _, _ = _scale_fig_size(figsize, textsize, rows, cols)
|
|
47
|
-
backend_kwargs.setdefault("figsize", figsize)
|
|
48
|
-
backend_kwargs.setdefault("squeeze", False)
|
|
49
|
-
|
|
50
|
-
if axes is None:
|
|
51
|
-
_, axes = create_axes_grid(length_plotters, rows, cols, backend_kwargs=backend_kwargs)
|
|
52
|
-
|
|
53
|
-
for i, ax_i in enumerate(np.ravel(axes)[:length_plotters]):
|
|
54
|
-
# All the kwargs are defined here beforehand
|
|
55
|
-
y_kwargs = matplotlib_kwarg_dealiaser(y_kwargs, "plot")
|
|
56
|
-
y_kwargs.setdefault("color", "C3")
|
|
57
|
-
y_kwargs.setdefault("marker", ".")
|
|
58
|
-
y_kwargs.setdefault("markersize", 15)
|
|
59
|
-
y_kwargs.setdefault("linewidth", 0)
|
|
60
|
-
y_kwargs.setdefault("zorder", 10)
|
|
61
|
-
y_kwargs.setdefault("label", "observed_data")
|
|
62
|
-
|
|
63
|
-
y_hat_plot_kwargs = matplotlib_kwarg_dealiaser(y_hat_plot_kwargs, "plot")
|
|
64
|
-
y_hat_plot_kwargs.setdefault("color", "C1")
|
|
65
|
-
y_hat_plot_kwargs.setdefault("alpha", 0.3)
|
|
66
|
-
y_hat_plot_kwargs.setdefault("markersize", 10)
|
|
67
|
-
y_hat_plot_kwargs.setdefault("marker", ".")
|
|
68
|
-
y_hat_plot_kwargs.setdefault("linewidth", 0)
|
|
69
|
-
|
|
70
|
-
y_hat_fill_kwargs = matplotlib_kwarg_dealiaser(y_hat_fill_kwargs, "fill_between")
|
|
71
|
-
y_hat_fill_kwargs.setdefault("color", "C3")
|
|
72
|
-
|
|
73
|
-
y_model_plot_kwargs = matplotlib_kwarg_dealiaser(y_model_plot_kwargs, "plot")
|
|
74
|
-
y_model_plot_kwargs.setdefault("color", "C6")
|
|
75
|
-
y_model_plot_kwargs.setdefault("alpha", 0.5)
|
|
76
|
-
y_model_plot_kwargs.setdefault("linewidth", 0.5)
|
|
77
|
-
y_model_plot_kwargs.setdefault("zorder", 9)
|
|
78
|
-
|
|
79
|
-
y_model_fill_kwargs = matplotlib_kwarg_dealiaser(y_model_fill_kwargs, "fill_between")
|
|
80
|
-
y_model_fill_kwargs.setdefault("color", "C0")
|
|
81
|
-
y_model_fill_kwargs.setdefault("linewidth", 0.5)
|
|
82
|
-
y_model_fill_kwargs.setdefault("zorder", 9)
|
|
83
|
-
y_model_fill_kwargs.setdefault("alpha", 0.5)
|
|
84
|
-
|
|
85
|
-
y_model_mean_kwargs = matplotlib_kwarg_dealiaser(y_model_mean_kwargs, "plot")
|
|
86
|
-
y_model_mean_kwargs.setdefault("color", "C6")
|
|
87
|
-
y_model_mean_kwargs.setdefault("linewidth", 0.8)
|
|
88
|
-
y_model_mean_kwargs.setdefault("zorder", 11)
|
|
89
|
-
|
|
90
|
-
y_var_name, _, _, y_plotters = y[i]
|
|
91
|
-
x_var_name, _, _, x_plotters = x[i]
|
|
92
|
-
ax_i.plot(x_plotters, y_plotters, **y_kwargs)
|
|
93
|
-
ax_i.set_xlabel(x_var_name)
|
|
94
|
-
ax_i.set_ylabel(y_var_name)
|
|
95
|
-
|
|
96
|
-
if y_hat is not None:
|
|
97
|
-
_, _, _, y_hat_plotters = y_hat[i]
|
|
98
|
-
if kind_pp == "samples":
|
|
99
|
-
for j in range(num_samples):
|
|
100
|
-
if xjitter is True:
|
|
101
|
-
jitter_scale = x_plotters[1] - x_plotters[0]
|
|
102
|
-
scale_high = jitter_scale * 0.2
|
|
103
|
-
x_plotters_jitter = x_plotters + np.random.uniform(
|
|
104
|
-
low=-scale_high, high=scale_high, size=len(x_plotters)
|
|
105
|
-
)
|
|
106
|
-
ax_i.plot(x_plotters_jitter, y_hat_plotters[..., j], **y_hat_plot_kwargs)
|
|
107
|
-
else:
|
|
108
|
-
ax_i.plot(x_plotters, y_hat_plotters[..., j], **y_hat_plot_kwargs)
|
|
109
|
-
ax_i.plot([], **y_hat_plot_kwargs, label="Posterior predictive samples")
|
|
110
|
-
else:
|
|
111
|
-
plot_hdi(x_plotters, y_hat_plotters, ax=ax_i, **y_hat_fill_kwargs)
|
|
112
|
-
ax_i.plot(
|
|
113
|
-
[], color=y_hat_fill_kwargs["color"], label="Posterior predictive samples"
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
if y_model is not None:
|
|
117
|
-
_, _, _, y_model_plotters = y_model[i]
|
|
118
|
-
|
|
119
|
-
if kind_model == "lines":
|
|
120
|
-
# y_model_plotters should be (points, samples)
|
|
121
|
-
y_points = y_model_plotters.shape[0]
|
|
122
|
-
if x_plotters.shape[0] == y_points:
|
|
123
|
-
for j in range(num_samples):
|
|
124
|
-
ax_i.plot(x_plotters, y_model_plotters[:, j], **y_model_plot_kwargs)
|
|
125
|
-
|
|
126
|
-
ax_i.plot([], **y_model_plot_kwargs, label="Uncertainty in mean")
|
|
127
|
-
y_model_mean = np.mean(y_model_plotters, axis=1)
|
|
128
|
-
ax_i.plot(x_plotters, y_model_mean, **y_model_mean_kwargs, label="Mean")
|
|
129
|
-
|
|
130
|
-
else:
|
|
131
|
-
plot_hdi(
|
|
132
|
-
x_plotters,
|
|
133
|
-
y_model_plotters,
|
|
134
|
-
fill_kwargs=y_model_fill_kwargs,
|
|
135
|
-
ax=ax_i,
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
ax_i.plot([], color=y_model_fill_kwargs["color"], label="Uncertainty in mean")
|
|
139
|
-
y_model_mean = np.mean(y_model_plotters, axis=0)
|
|
140
|
-
ax_i.plot(x_plotters, y_model_mean, **y_model_mean_kwargs, label="Mean")
|
|
141
|
-
|
|
142
|
-
if legend:
|
|
143
|
-
ax_i.legend(fontsize=xt_labelsize, loc="upper left")
|
|
144
|
-
if grid:
|
|
145
|
-
ax_i.grid(True)
|
|
146
|
-
|
|
147
|
-
if backend_show(show):
|
|
148
|
-
plt.show()
|
|
149
|
-
return axes
|