1
"""Bokeh Autocorrplot."""
2 4
import numpy as np
3 4
from bokeh.models import DataRange1d
4 4
from bokeh.models.annotations import Title
5

6 4
from ....stats import autocorr
7 4
from ...plot_utils import _scale_fig_size, make_label
8 4
from .. import show_layout
9 4
from . import backend_kwarg_defaults, create_axes_grid
10

11

12 4
def plot_autocorr(
13
    axes,
14
    plotters,
15
    max_lag,
16
    figsize,
17
    rows,
18
    cols,
19
    combined,
20
    textsize,
21
    backend_config,
22
    backend_kwargs,
23
    show,
24
):
25
    """Bokeh autocorrelation plot."""
26 4
    if backend_config is None:
27 4
        backend_config = {}
28

29 4
    len_y = plotters[0][2].size
30 4
    backend_config.setdefault("bounds_x_range", (0, len_y))
31

32 4
    backend_config = {
33
        **backend_kwarg_defaults(
34
            ("bounds_y_range", "plot.bokeh.bounds_y_range"),
35
        ),
36
        **backend_config,
37
    }
38

39 4
    if backend_kwargs is None:
40 4
        backend_kwargs = {}
41

42 4
    backend_kwargs = {
43
        **backend_kwarg_defaults(
44
            ("dpi", "plot.bokeh.figure.dpi"),
45
        ),
46
        **backend_kwargs,
47
    }
48

49 4
    figsize, _, _, _, line_width, _ = _scale_fig_size(figsize, textsize, rows, cols)
50

51 4
    if axes is None:
52 4
        axes = create_axes_grid(
53
            len(plotters),
54
            rows,
55
            cols,
56
            figsize=figsize,
57
            sharex=True,
58
            sharey=True,
59
            backend_kwargs=backend_kwargs,
60
        )
61
    else:
62 0
        axes = np.atleast_2d(axes)
63

64 4
    data_range_x = DataRange1d(
65
        start=0, end=max_lag, bounds=backend_config["bounds_x_range"], min_interval=5
66
    )
67 4
    data_range_y = DataRange1d(
68
        start=-1, end=1, bounds=backend_config["bounds_y_range"], min_interval=0.1
69
    )
70

71 4
    for (var_name, selection, x), ax in zip(
72
        plotters, (item for item in axes.flatten() if item is not None)
73
    ):
74 4
        x_prime = x
75 4
        if combined:
76 4
            x_prime = x.flatten()
77 4
        y = autocorr(x_prime)
78

79 4
        ax.segment(
80
            x0=np.arange(len(y)),
81
            y0=0,
82
            x1=np.arange(len(y)),
83
            y1=y,
84
            line_width=line_width,
85
            line_color="black",
86
        )
87 4
        ax.line([0, 0], [0, max_lag], line_color="steelblue")
88

89 4
        title = Title()
90 4
        title.text = make_label(var_name, selection)
91 4
        ax.title = title
92 4
        ax.x_range = data_range_x
93 4
        ax.y_range = data_range_y
94

95 4
    show_layout(axes, show)
96

97 4
    return axes

Read our documentation on viewing source code .

Loading