Skip to content

Bokeh

pytao.plotting.bokeh

Classes

pytao.plotting.bokeh.BokehAppCreator
BokehAppCreator(manager, graphs, share_x=None, include_variables=False, grid=None, width=None, height=None, include_layout=False, graph_sizing_mode=None, layout_height=None, xlim=None, ylim=None)

A composite Bokeh application creator made up of 1 or more graphs.

This can be used to: * Generate a static HTML page without Python widgets * Generate a Notebook (or standalone) application with Python widgets

Interactive widgets will use the Tao object to adjust variables during callbacks resulting from user interaction.

Source code in pytao/plotting/bokeh.py
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
def __init__(
    self,
    manager: Union[BokehGraphManager, NotebookGraphManager],
    graphs: List[AnyGraph],
    share_x: Optional[bool] = None,
    include_variables: bool = False,
    grid: Optional[Tuple[int, int]] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
    include_layout: bool = False,
    graph_sizing_mode: Optional[SizingModeType] = None,
    layout_height: Optional[int] = None,
    xlim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
    ylim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
) -> None:
    if not len(graphs):
        raise ValueError("BokehAppCreator requires 1 or more graph")

    if any(isinstance(graph, LatticeLayoutGraph) for graph in graphs):
        include_layout = False
    elif not any(graph.is_s_plot for graph in graphs):
        include_layout = False

    if not grid:
        grid = (len(graphs), 1)

    if include_layout:
        grid = (grid[0] + 1, grid[1])

    if include_variables:
        variables = Variable.from_tao_all(manager.tao)
    else:
        variables = []

    self.manager = manager
    self.graphs = graphs
    self.share_x = share_x
    self.variables = variables
    self.grid = grid
    self.width = width
    self.height = height
    self.graph_sizing_mode = graph_sizing_mode
    self.include_layout = include_layout
    self.layout_height = layout_height
    self.xlim = fix_grid_limits(xlim, num_graphs=len(graphs))
    self.ylim = fix_grid_limits(ylim, num_graphs=len(graphs))
Functions
pytao.plotting.bokeh.BokehAppCreator.create_state
create_state()

Create an independent application state based on the graph data.

Source code in pytao/plotting/bokeh.py
1360
1361
1362
1363
1364
1365
1366
1367
1368
def create_state(self) -> BokehAppState:
    """Create an independent application state based on the graph data."""
    pairs, layout_pairs = self._create_figures()
    grid = self._grid_figures(pairs, layout_pairs)
    return BokehAppState(
        pairs=pairs,
        layout_pairs=layout_pairs,
        grid=grid,
    )
pytao.plotting.bokeh.BokehGraphManager
BokehGraphManager(tao)

Bases: GraphManager

Bokeh backend graph manager - for non-Jupyter contexts.

Source code in pytao/plotting/plot.py
1223
1224
1225
1226
def __init__(self, tao: Tao) -> None:
    self.tao = tao
    self.regions = {}
    self._to_place = {}
Functions
pytao.plotting.bokeh.BokehGraphManager.plot
plot(template, *, region_name=None, include_layout=True, sizing_mode=None, width=None, height=None, layout_height=None, share_x=None, xlim=None, ylim=None, save=None, curves=None, settings=None)

Plot a graph with Bokeh.

Parameters:

Name Type Description Default
template str

Graph template name.

required
region_name str

Graph region name.

None
include_layout bool

Include a layout plot at the bottom, if not already placed and if appropriate (i.e., another plot uses longitudinal coordinates on the x-axis).

True
sizing_mode Optional[SizingModeType]

Set the sizing mode for all graphs. Default is configured on a per-graph basis, typically "inherit".

None
width int

Width of each plot.

None
height int

Height of each plot.

None
layout_height int

Height of the layout plot.

None
share_x bool or None

Share x-axes where sensible (None) or force sharing x-axes (True) for all plots.

None
xlim (float, float)

X axis limits.

None
ylim (float, float)

Y axis limits.

None
curves Dict[int, TaoCurveSettings]

Dictionary of curve index to curve settings. These settings will be applied to the placed graph prior to plotting.

None
settings TaoGraphSettings

Graph customization settings.

None
save str or bool

Save the plot to a static HTML file with the given name. If True, saves to a filename based on the plot title.

None

Returns:

Type Description
list of graphs
BokehAppCreator
Source code in pytao/plotting/bokeh.py
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
def plot(
    self,
    template: str,
    *,
    region_name: Optional[str] = None,
    include_layout: bool = True,
    sizing_mode: Optional[SizingModeType] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
    layout_height: Optional[int] = None,
    share_x: Optional[bool] = None,
    xlim: Optional[Tuple[float, float]] = None,
    ylim: Optional[Tuple[float, float]] = None,
    save: Union[bool, str, pathlib.Path, None] = None,
    curves: Optional[Dict[int, TaoCurveSettings]] = None,
    settings: Optional[TaoGraphSettings] = None,
) -> Tuple[List[AnyGraph], BokehAppCreator]:
    """
    Plot a graph with Bokeh.

    Parameters
    ----------
    template : str
        Graph template name.
    region_name : str, optional
        Graph region name.
    include_layout : bool
        Include a layout plot at the bottom, if not already placed and if
        appropriate (i.e., another plot uses longitudinal coordinates on
        the x-axis).
    sizing_mode : Optional[SizingModeType]
        Set the sizing mode for all graphs.  Default is configured on a
        per-graph basis, typically "inherit".
    width : int, optional
        Width of each plot.
    height : int, optional
        Height of each plot.
    layout_height : int, optional
        Height of the layout plot.
    share_x : bool or None, default=None
        Share x-axes where sensible (`None`) or force sharing x-axes (True)
        for all plots.
    xlim : (float, float), optional
        X axis limits.
    ylim : (float, float), optional
        Y axis limits.
    curves : Dict[int, TaoCurveSettings], optional
        Dictionary of curve index to curve settings. These settings will be
        applied to the placed graph prior to plotting.
    settings : TaoGraphSettings, optional
        Graph customization settings.
    save : str or bool, optional
        Save the plot to a static HTML file with the given name.
        If `True`, saves to a filename based on the plot title.

    Returns
    -------
    list of graphs

    BokehAppCreator
    """
    graphs = self.prepare_graphs_by_name(
        template_name=template,
        region_name=region_name,
        curves=curves,
        settings=settings,
        xlim=xlim,
        ylim=ylim,
    )

    if not graphs:
        raise UnsupportedGraphError(f"No supported plots from this template: {template}")

    app = BokehAppCreator(
        manager=self,
        graphs=graphs,
        share_x=share_x,
        include_variables=False,
        grid=None,
        width=width or _Defaults.width,
        height=height or _Defaults.height,
        layout_height=layout_height or _Defaults.layout_height,
        include_layout=include_layout,
        graph_sizing_mode=sizing_mode,
        xlim=[xlim],
        ylim=[ylim],
    )

    if save:
        if save is True:
            save = ""
        filename = app.save(save)
        logger.info(f"Saving plot to {filename!r}")

    return graphs, app
pytao.plotting.bokeh.BokehGraphManager.plot_field
plot_field(ele_id, *, colormap=None, radius=0.015, num_points=100, x_scale=1.0, width=None, height=None, save=None)

Plot field information for a given element.

Parameters:

Name Type Description Default
ele_id str

Element ID.

required
colormap str

Colormap for the plot. Matplotlib defaults to "PRGn_r", and bokeh defaults to "".

None
radius float

Radius.

0.015
num_points int

Number of data points.

100
width int
None
height int
None
save Path or str

Save the plot to the given filename.

None

Returns:

Type Description
ElementField
figure
Source code in pytao/plotting/bokeh.py
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
def plot_field(
    self,
    ele_id: str,
    *,
    colormap: Optional[str] = None,
    radius: float = 0.015,
    num_points: int = 100,
    x_scale: float = 1.0,
    width: Optional[int] = None,
    height: Optional[int] = None,
    save: Union[bool, str, pathlib.Path, None] = None,
):
    """
    Plot field information for a given element.

    Parameters
    ----------
    ele_id : str
        Element ID.
    colormap : str, optional
        Colormap for the plot.
        Matplotlib defaults to "PRGn_r", and bokeh defaults to "".
    radius : float, default=0.015
        Radius.
    num_points : int, default=100
        Number of data points.
    width : int, optional
    height : int, optional
    save : pathlib.Path or str, optional
        Save the plot to the given filename.

    Returns
    -------
    ElementField

    figure
    """
    field = ElementField.from_tao(self.tao, ele_id, num_points=num_points, radius=radius)
    fig = figure(title=f"Field of {ele_id}")

    palette = colormap or _Defaults.palette

    source = _fields_to_data_source([field], x_scale=x_scale)
    cmap = bokeh.models.LinearColorMapper(
        palette=palette or _Defaults.palette,
        low=np.min(source.data["by"]),
        high=np.max(source.data["by"]),
    )

    fig.image(
        image="by",
        x="x",
        y=-1,
        dw="dw",
        dh="dh",
        color_mapper=cmap,
        source=source,
        name="field_images",
    )
    color_bar = bokeh.models.ColorBar(color_mapper=cmap, location=(0, 0))
    fig.add_layout(color_bar, "right")

    fig.frame_width = width or _Defaults.width
    fig.frame_height = height or _Defaults.height

    if save:
        if save is True:
            save = f"{ele_id}_field.html"
        if not pathlib.Path(save).suffix:
            save = f"{save}.html"
        filename = bokeh.io.save(fig, filename=save)
        logger.info(f"Saving plot to {filename!r}")

    return field, fig
pytao.plotting.bokeh.BokehGraphManager.plot_grid
plot_grid(templates, grid, *, include_layout=False, share_x=None, width=None, height=None, figsize=None, layout_height=None, xlim=None, ylim=None, curves=None, settings=None, save=None)

Plot graphs on a grid with Bokeh.

Parameters:

Name Type Description Default
templates list of str

Graph template names.

required
grid (nrows, ncols)

Grid the provided graphs into this many rows and columns.

required
include_layout bool

Include a layout plot at the bottom of each column.

False
share_x bool or None

Share x-axes where sensible (None) or force sharing x-axes (True) for all plots.

None
figsize (int, int)

Figure size. Alternative to specifying width and height separately. This takes precedence over width and height.

None
width int

Width of the whole plot.

None
height int

Height of the whole plot.

None
layout_height int

Height of the layout plot.

None
xlim list of (float, float)

X axis limits for each graph.

None
ylim list of (float, float)

Y axis limits for each graph.

None
curves list of Dict[int, TaoCurveSettings]

One dictionary per graph, with each dictionary mapping the curve index to curve settings. These settings will be applied to the placed graphs prior to plotting.

None
settings list of TaoGraphSettings

Graph customization settings, per graph.

None
save Path or str

Save the plot to the given filename.

None

Returns:

Type Description
list of graphs
BokehAppCreator
Source code in pytao/plotting/bokeh.py
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
def plot_grid(
    self,
    templates: List[str],
    grid: Tuple[int, int],
    *,
    include_layout: bool = False,
    share_x: Optional[bool] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
    figsize: Optional[Tuple[int, int]] = None,
    layout_height: Optional[int] = None,
    xlim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
    ylim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
    curves: Optional[List[CurveIndexToCurve]] = None,
    settings: Optional[List[TaoGraphSettings]] = None,
    save: Union[bool, str, pathlib.Path, None] = None,
):
    """
    Plot graphs on a grid with Bokeh.

    Parameters
    ----------
    templates : list of str
        Graph template names.
    grid : (nrows, ncols), optional
        Grid the provided graphs into this many rows and columns.
    include_layout : bool, default=False
        Include a layout plot at the bottom of each column.
    share_x : bool or None, default=None
        Share x-axes where sensible (`None`) or force sharing x-axes (True)
        for all plots.
    figsize : (int, int), optional
        Figure size. Alternative to specifying `width` and `height`
        separately.  This takes precedence over `width` and `height`.
    width : int, optional
        Width of the whole plot.
    height : int, optional
        Height of the whole plot.
    layout_height : int, optional
        Height of the layout plot.
    xlim : list of (float, float), optional
        X axis limits for each graph.
    ylim : list of (float, float), optional
        Y axis limits for each graph.
    curves : list of Dict[int, TaoCurveSettings], optional
        One dictionary per graph, with each dictionary mapping the curve
        index to curve settings. These settings will be applied to the
        placed graphs prior to plotting.
    settings : list of TaoGraphSettings, optional
        Graph customization settings, per graph.
    save : pathlib.Path or str, optional
        Save the plot to the given filename.

    Returns
    -------
    list of graphs

    BokehAppCreator
    """
    graphs = self.prepare_grid_by_names(
        template_names=templates,
        curves=curves,
        settings=settings,
        xlim=xlim,
        ylim=ylim,
    )

    if figsize is not None:
        width, height = figsize

    app = BokehAppCreator(
        manager=self,
        graphs=graphs,
        share_x=share_x,
        include_variables=False,
        grid=grid,
        width=width or _Defaults.width,
        height=height or _Defaults.stacked_height,
        layout_height=layout_height or _Defaults.layout_height,
        include_layout=include_layout,
        xlim=xlim,
        ylim=ylim,
    )

    if save:
        if save is True:
            save = ""
        filename = app.save(save)
        logger.info(f"Saving plot to {filename!r}")
    return graphs, app
pytao.plotting.bokeh.BokehGraphManager.to_bokeh_graph
to_bokeh_graph(graph)

Create a Bokeh graph instance from the backend-agnostic AnyGraph version.

For example, BasicGraph becomes BokehBasicGraph.

Parameters:

Name Type Description Default
graph AnyGraph
required

Returns:

Type Description
AnyBokehGraph
Source code in pytao/plotting/bokeh.py
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
def to_bokeh_graph(self, graph: AnyGraph) -> AnyBokehGraph:
    """
    Create a Bokeh graph instance from the backend-agnostic AnyGraph version.

    For example, `BasicGraph` becomes `BokehBasicGraph`.

    Parameters
    ----------
    graph : AnyGraph

    Returns
    -------
    AnyBokehGraph
    """
    if isinstance(graph, BasicGraph):
        return BokehBasicGraph(self, graph)
    elif isinstance(graph, LatticeLayoutGraph):
        return BokehLatticeLayoutGraph(self, graph)
    elif isinstance(graph, FloorPlanGraph):
        return BokehFloorPlanGraph(self, graph)
    raise NotImplementedError(type(graph).__name__)
pytao.plotting.bokeh.NotebookGraphManager
NotebookGraphManager(tao)

Bases: BokehGraphManager

Jupyter notebook Bokeh backend graph manager.

Source code in pytao/plotting/plot.py
1223
1224
1225
1226
def __init__(self, tao: Tao) -> None:
    self.tao = tao
    self.regions = {}
    self._to_place = {}
Functions
pytao.plotting.bokeh.NotebookGraphManager.plot
plot(template, *, region_name=None, include_layout=True, sizing_mode=None, width=None, height=None, layout_height=None, share_x=None, vars=False, xlim=None, ylim=None, notebook_handle=False, save=None, curves=None, settings=None)

Plot a graph with Bokeh.

Parameters:

Name Type Description Default
template str

Graph template name.

required
region_name str

Graph region name.

None
include_layout bool

Include a layout plot at the bottom, if not already placed and if appropriate (i.e., another plot uses longitudinal coordinates on the x-axis).

True
sizing_mode Optional[SizingModeType]

Set the sizing mode for all graphs. Default is configured on a per-graph basis, typically "inherit".

None
width int

Width of each plot.

None
height int

Height of each plot.

None
layout_height int

Height of the layout plot.

None
share_x bool or None

Share x-axes where sensible (None) or force sharing x-axes (True) for all plots.

None
vars bool

Show Tao variables as adjustable widgets, like "single mode".

False
xlim (float, float)

X axis limits.

None
ylim (float, float)

Y axis limits.

None
curves Dict[int, TaoCurveSettings]

Dictionary of curve index to curve settings. These settings will be applied to the placed graph prior to plotting.

None
settings TaoGraphSettings

Graph customization settings.

None
save str or bool

Save the plot to a static HTML file with the given name. If True, saves to a filename based on the plot title.

None

Returns:

Type Description
BokehAppCreator
Source code in pytao/plotting/bokeh.py
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
def plot(
    self,
    template: str,
    *,
    region_name: Optional[str] = None,
    include_layout: bool = True,
    sizing_mode: Optional[SizingModeType] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
    layout_height: Optional[int] = None,
    share_x: Optional[bool] = None,
    vars: bool = False,
    xlim: Optional[Limit] = None,
    ylim: Optional[Limit] = None,
    notebook_handle: bool = False,
    save: Union[bool, str, pathlib.Path, None] = None,
    curves: Optional[Dict[int, TaoCurveSettings]] = None,
    settings: Optional[TaoGraphSettings] = None,
) -> Tuple[List[AnyGraph], BokehAppCreator]:
    """
    Plot a graph with Bokeh.

    Parameters
    ----------
    template : str
        Graph template name.
    region_name : str, optional
        Graph region name.
    include_layout : bool
        Include a layout plot at the bottom, if not already placed and if
        appropriate (i.e., another plot uses longitudinal coordinates on
        the x-axis).
    sizing_mode : Optional[SizingModeType]
        Set the sizing mode for all graphs.  Default is configured on a
        per-graph basis, typically "inherit".
    width : int, optional
        Width of each plot.
    height : int, optional
        Height of each plot.
    layout_height : int, optional
        Height of the layout plot.
    share_x : bool or None, default=None
        Share x-axes where sensible (`None`) or force sharing x-axes (True)
        for all plots.
    vars : bool, default=False
        Show Tao variables as adjustable widgets, like "single mode".
    xlim : (float, float), optional
        X axis limits.
    ylim : (float, float), optional
        Y axis limits.
    curves : Dict[int, TaoCurveSettings], optional
        Dictionary of curve index to curve settings. These settings will be
        applied to the placed graph prior to plotting.
    settings : TaoGraphSettings, optional
        Graph customization settings.
    save : str or bool, optional
        Save the plot to a static HTML file with the given name.
        If `True`, saves to a filename based on the plot title.

    Returns
    -------
    BokehAppCreator
    """
    graphs, app = super().plot(
        region_name=region_name,
        template=template,
        include_layout=include_layout,
        sizing_mode=sizing_mode,
        width=width,
        height=height,
        layout_height=layout_height,
        xlim=xlim,
        ylim=ylim,
        curves=curves,
        settings=settings,
        share_x=share_x,
        save=save,
    )

    if vars:
        app.variables = Variable.from_tao_all(self.tao)

    bokeh.plotting.show(
        app.create_full_app(),
        notebook_handle=notebook_handle,
    )
    return graphs, app
pytao.plotting.bokeh.NotebookGraphManager.plot_field
plot_field(ele_id, *, colormap=None, radius=0.015, num_points=100, width=None, height=None, x_scale=1.0, save=None)

Plot field information for a given element.

Parameters:

Name Type Description Default
ele_id str

Element ID.

required
colormap str

Colormap for the plot. Matplotlib defaults to "PRGn_r", and bokeh defaults to "".

None
radius float

Radius.

0.015
num_points int

Number of data points.

100
width int
None
height int
None
save Path or str

Save the plot to the given filename.

None
Source code in pytao/plotting/bokeh.py
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
def plot_field(
    self,
    ele_id: str,
    *,
    colormap: Optional[str] = None,
    radius: float = 0.015,
    num_points: int = 100,
    width: Optional[int] = None,
    height: Optional[int] = None,
    x_scale: float = 1.0,
    save: Union[bool, str, pathlib.Path, None] = None,
):
    """
    Plot field information for a given element.

    Parameters
    ----------
    ele_id : str
        Element ID.
    colormap : str, optional
        Colormap for the plot.
        Matplotlib defaults to "PRGn_r", and bokeh defaults to "".
    radius : float, default=0.015
        Radius.
    num_points : int, default=100
        Number of data points.
    width : int, optional
    height : int, optional
    save : pathlib.Path or str, optional
        Save the plot to the given filename.
    """
    field, fig = super().plot_field(
        ele_id,
        colormap=colormap,
        radius=radius,
        num_points=num_points,
        width=width,
        height=height,
        save=save,
        x_scale=x_scale,
    )
    bokeh.plotting.show(fig, notebook_handle=True)

    return field, fig
pytao.plotting.bokeh.NotebookGraphManager.plot_grid
plot_grid(templates, grid, *, curves=None, settings=None, include_layout=False, share_x=None, vars=False, figsize=None, layout_height=None, xlim=None, ylim=None, width=None, height=None, save=None)

Plot graphs on a grid with Bokeh.

Parameters:

Name Type Description Default
templates list of str

Graph template names.

required
grid (nrows, ncols)

Grid the provided graphs into this many rows and columns.

required
include_layout bool

Include a layout plot at the bottom of each column.

False
share_x bool or None

Share x-axes where sensible (None) or force sharing x-axes (True) for all plots.

None
vars bool

Show Tao variables as adjustable widgets, like "single mode".

False
figsize (int, int)

Figure size. Alternative to specifying width and height separately. This takes precedence over width and height.

None
width int

Width of the whole plot.

None
height int

Height of the whole plot.

None
layout_height int

Height of the layout plot.

None
xlim list of (float, float)

X axis limits for each graph.

None
ylim list of (float, float)

Y axis limits for each graph.

None
curves list of Dict[int, TaoCurveSettings]

One dictionary per graph, with each dictionary mapping the curve index to curve settings. These settings will be applied to the placed graphs prior to plotting.

None
settings list of TaoGraphSettings

Graph customization settings, per graph.

None
save Path or str

Save the plot to the given filename.

None

Returns:

Type Description
list of graphs
BokehAppCreator
Source code in pytao/plotting/bokeh.py
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
def plot_grid(
    self,
    templates: List[str],
    grid: Tuple[int, int],
    *,
    curves: Optional[List[CurveIndexToCurve]] = None,
    settings: Optional[List[TaoGraphSettings]] = None,
    include_layout: bool = False,
    share_x: Optional[bool] = None,
    vars: bool = False,
    figsize: Optional[Tuple[int, int]] = None,
    layout_height: Optional[int] = None,
    xlim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
    ylim: Union[OptionalLimit, Sequence[OptionalLimit]] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
    save: Union[bool, str, pathlib.Path, None] = None,
):
    """
    Plot graphs on a grid with Bokeh.

    Parameters
    ----------
    templates : list of str
        Graph template names.
    grid : (nrows, ncols), optional
        Grid the provided graphs into this many rows and columns.
    include_layout : bool, default=False
        Include a layout plot at the bottom of each column.
    share_x : bool or None, default=None
        Share x-axes where sensible (`None`) or force sharing x-axes (True)
        for all plots.
    vars : bool, default=False
        Show Tao variables as adjustable widgets, like "single mode".
    figsize : (int, int), optional
        Figure size. Alternative to specifying `width` and `height`
        separately.  This takes precedence over `width` and `height`.
    width : int, optional
        Width of the whole plot.
    height : int, optional
        Height of the whole plot.
    layout_height : int, optional
        Height of the layout plot.
    xlim : list of (float, float), optional
        X axis limits for each graph.
    ylim : list of (float, float), optional
        Y axis limits for each graph.
    curves : list of Dict[int, TaoCurveSettings], optional
        One dictionary per graph, with each dictionary mapping the curve
        index to curve settings. These settings will be applied to the
        placed graphs prior to plotting.
    settings : list of TaoGraphSettings, optional
        Graph customization settings, per graph.
    save : pathlib.Path or str, optional
        Save the plot to the given filename.

    Returns
    -------
    list of graphs

    BokehAppCreator
    """
    graphs, app = super().plot_grid(
        templates=templates,
        grid=grid,
        curves=curves,
        settings=settings,
        include_layout=include_layout,
        share_x=share_x,
        figsize=figsize,
        width=width,
        height=height,
        xlim=xlim,
        ylim=ylim,
        layout_height=layout_height,
        save=save,
    )
    if vars:
        app.variables = Variable.from_tao_all(self.tao)
    bokeh.plotting.show(app.create_full_app())
    return graphs, app

Functions

pytao.plotting.bokeh.set_defaults
set_defaults(width=None, height=None, stacked_height=None, layout_height=None, palette=None, show_bokeh_logo=None, tools=None, grid_toolbar_location=None, lattice_layout_tools=None, floor_plan_tools=None, floor_plan_annotate_elements=None, layout_font_size=None, floor_plan_font_size=None, limit_scale_factor=None, max_data_points=None, variables_per_row=None, show_sliders=None, line_width_scale=None, floor_line_width_scale=None)

Change defaults used for Bokeh plots.

Parameters:

Name Type Description Default
width int

Plot default width.

None
height int

Plot default height.

None
stacked_height int

Stacked plot default height (plot_grid)

None
layout_height int

Layout plot height.

None
palette str

Palette for plot_field.

None
show_bokeh_logo bool

Show Bokeh logo on each plot.

None
tools str

Bokeh tools to use.

"pan,wheel_zoom,box_zoom,reset,hover,crosshair"
grid_toolbar_location str

Toolbar location for gridded plots.

"right"
lattice_layout_tools str

Bokeh tools to use specifically for lattice layouts.

None
floor_plan_tools str

Bokeh tools to use specifically for floor plan layouts.

None
layout_font_size str

Font size to use in lattice layouts.

None
floor_plan_font_size str

Font size to use in floor plan layouts.

None
limit_scale_factor float

View limits from Tao are scaled by this factor. This can be used to ensure that all data is visible despite drawing method differences.

1.01
max_data_points int

Maximum number of data points to show in the slider.

None
variables_per_row int

Variables to list per row when in single mode (i.e., vars=True).

2
show_sliders bool

Show sliders alongside the spinners in single mode.

True
line_width_scale float

Plot line width scaling factor applied to Tao's line width.

1.0
floor_line_width_scale float

Floor plan line width scaling factor applied to Tao's line width.

0.5
Source code in pytao/plotting/bokeh.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def set_defaults(
    width: Optional[int] = None,
    height: Optional[int] = None,
    stacked_height: Optional[int] = None,
    layout_height: Optional[int] = None,
    palette: Optional[str] = None,
    show_bokeh_logo: Optional[bool] = None,
    tools: Optional[str] = None,
    grid_toolbar_location: Optional[str] = None,
    lattice_layout_tools: Optional[str] = None,
    floor_plan_tools: Optional[str] = None,
    floor_plan_annotate_elements: Optional[bool] = None,
    layout_font_size: Optional[str] = None,
    floor_plan_font_size: Optional[str] = None,
    limit_scale_factor: Optional[float] = None,
    max_data_points: Optional[int] = None,
    variables_per_row: Optional[int] = None,
    show_sliders: Optional[bool] = None,
    line_width_scale: Optional[float] = None,
    floor_line_width_scale: Optional[float] = None,
):
    """
    Change defaults used for Bokeh plots.

    Parameters
    ----------
    width : int, optional
        Plot default width.
    height : int, optional
        Plot default height.
    stacked_height : int, optional
        Stacked plot default height (`plot_grid`)
    layout_height : int, optional
        Layout plot height.
    palette : str, optional
        Palette for `plot_field`.
    show_bokeh_logo : bool, optional
        Show Bokeh logo on each plot.
    tools : str, default="pan,wheel_zoom,box_zoom,reset,hover,crosshair"
        Bokeh tools to use.
    grid_toolbar_location : str, default="right"
        Toolbar location for gridded plots.
    lattice_layout_tools : str, optional
        Bokeh tools to use specifically for lattice layouts.
    floor_plan_tools : str, optional
        Bokeh tools to use specifically for floor plan layouts.
    layout_font_size : str, optional
        Font size to use in lattice layouts.
    floor_plan_font_size : str, optional
        Font size to use in floor plan layouts.
    limit_scale_factor : float, default=1.01
        View limits from Tao are scaled by this factor.  This can be used to
        ensure that all data is visible despite drawing method differences.
    max_data_points : int, optional
        Maximum number of data points to show in the slider.
    variables_per_row : int, default=2
        Variables to list per row when in single mode (i.e., `vars=True`).
    show_sliders : bool, default=True
        Show sliders alongside the spinners in single mode.
    line_width_scale : float, default=1.0
        Plot line width scaling factor applied to Tao's line width.
    floor_line_width_scale : float, default=0.5
        Floor plan line width scaling factor applied to Tao's line width.
    """

    if width is not None:
        _Defaults.width = int(width)
    if height is not None:
        _Defaults.height = int(height)
    if stacked_height is not None:
        _Defaults.stacked_height = int(stacked_height)
    if layout_height is not None:
        _Defaults.layout_height = int(layout_height)
    if palette is not None:
        _Defaults.palette = palette
    if show_bokeh_logo is not None:
        _Defaults.show_bokeh_logo = bool(show_bokeh_logo)
    if tools is not None:
        _Defaults.tools = tools
    if grid_toolbar_location is not None:
        _Defaults.grid_toolbar_location = grid_toolbar_location
    if lattice_layout_tools is not None:
        _Defaults.lattice_layout_tools = lattice_layout_tools
    if floor_plan_tools is not None:
        _Defaults.floor_plan_tools = floor_plan_tools
    if floor_plan_annotate_elements is not None:
        _Defaults.floor_plan_annotate_elements = floor_plan_annotate_elements
    if layout_font_size is not None:
        _Defaults.layout_font_size = layout_font_size
    if floor_plan_font_size is not None:
        _Defaults.floor_plan_font_size = floor_plan_font_size
    if limit_scale_factor is not None:
        _Defaults.limit_scale_factor = float(limit_scale_factor)
    if max_data_points is not None:
        _Defaults.max_data_points = int(max_data_points)
    if variables_per_row is not None:
        _Defaults.variables_per_row = int(variables_per_row)
    if show_sliders is not None:
        _Defaults.show_sliders = bool(show_sliders)
    if line_width_scale is not None:
        _Defaults.line_width_scale = float(line_width_scale)
    if floor_line_width_scale is not None:
        _Defaults.floor_line_width_scale = float(floor_line_width_scale)
    return {
        key: value
        for key, value in vars(_Defaults).items()
        if not key.startswith("_") and key not in {"get_size_for_class"}
    }