bokeh.layouts#

用于排列bokeh布局对象的函数。

#

column(children: list[UIElement], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, **kwargs: Any) Column[source]#
column(*children: UIElement, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, **kwargs: Any) Column

创建一个Bokeh布局对象的列。强制所有对象具有相同的sizing_mode,这是复杂布局工作所必需的。

Parameters:
  • children (LayoutDOM 的列表) – 列的实例列表。可以是以下任意一种 - Plot, Widget, Row, Column, Spacer.

  • sizing_mode ("fixed", "stretch_both", "scale_width", "scale_height", "scale_both") – 布局中的项目如何调整大小以填充可用空间。默认值为 "fixed"。有关不同模式的更多信息,请参阅 sizing_modeLayoutDOM 上的描述。

Returns:

一列具有相同sizing_mode的LayoutDOM对象。

Return type:

Column

示例

>>> column(plot1, plot2)
>>> column(children=[widgets, plot], sizing_mode='stretch_both')

网格#

grid(children: list[UIElement | list[UIElement | list[Any]]], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None) GridBox[source]#
grid(children: Row | Column, *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None) GridBox
grid(children: list[UIElement | None], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, nrows: int) GridBox
grid(children: list[UIElement | None], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, ncols: int) GridBox
grid(children: list[UIElement | None], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, nrows: int, ncols: int) GridBox
grid(children: str, *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None) GridBox

方便地创建一个可布局对象的网格。

网格是通过使用GridBox模型创建的。这提供了对网格布局的最大控制,但也可能很繁琐,并且在实际应用中可能导致代码难以阅读。grid()函数通过减少控制级别来弥补这一点,但反过来提供了一个更方便的API。

支持的格式:

  1. 可布局对象的嵌套列表。假设顶层列表表示一列,并在后续嵌套级别中交替使用行和列。可以使用None进行填充。

    >>> grid([p1, [[p2, p3], p4]])
    GridBox(children=[
        (p1, 0, 0, 1, 2),
        (p2, 1, 0, 1, 1),
        (p3, 2, 0, 1, 1),
        (p4, 1, 1, 2, 1),
    ])
    
  2. 嵌套的RowColumn实例。与第一种模式类似,只是它使用嵌套的RowColumn模型,而不是使用嵌套列表。这可能比前者更具可读性。但请注意,只有未设置sizing_mode的模型才会被使用。

    >>> grid(column(p1, row(column(p2, p3), p4)))
    GridBox(children=[
        (p1, 0, 0, 1, 2),
        (p2, 1, 0, 1, 1),
        (p3, 2, 0, 1, 1),
        (p4, 1, 1, 2, 1),
    ])
    
  3. 可布局对象的平面列表。这需要设置nrows和/或ncols。输入列表将相应地重新排列成一个二维数组。可以使用None进行填充。

    >>> grid([p1, p2, p3, p4], ncols=2)
    GridBox(children=[
        (p1, 0, 0, 1, 1),
        (p2, 0, 1, 1, 1),
        (p3, 1, 0, 1, 1),
        (p4, 1, 1, 1, 1),
    ])
    

gridplot#

gridplot(children: list[UIElement | None], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, toolbar_location: Literal['above', 'below', 'left', 'right'] | None = 'above', ncols: int, width: int | None = None, height: int | None = None, toolbar_options: dict[ToolbarOptions, Any] | None = None, merge_tools: bool = True) GridPlot[源代码]#
gridplot(children: list[list[UIElement | None]], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, toolbar_location: Literal['above', 'below', 'left', 'right'] | None = 'above', ncols: None = None, width: int | None = None, height: int | None = None, toolbar_options: dict[ToolbarOptions, Any] | None = None, merge_tools: bool = True) GridPlot

创建一个在单独画布上渲染的绘图网格。

gridplot 函数为网格中的所有图表构建一个单一的工具栏。gridplot 设计用于布局一组图表。对于一般的网格布局,请使用 layout() 函数。

Parameters:
  • children (列表或列表的列表,包含 Plot) – 要在网格中显示的绘图数组,作为 Plot 对象的列表的列表传递。如果要在网格中留空某个位置,请在 children 列表中为该位置传递 None。如果使用 ncols 调用,则为 Plot 的列表。

  • sizing_mode ("fixed", "stretch_both", "scale_width", "scale_height", "scale_both") – 布局中的项目如何调整大小以填充可用空间。默认值为 "fixed"。有关不同模式的更多信息,请参阅 sizing_modeLayoutDOM 上的描述。

  • toolbar_location (above, below, left, right) – 工具栏将相对于网格的位置。默认是 above。如果设置为None,则不会将工具栏附加到网格上。

  • ncols (int, 可选) – 指定你希望在网格中显示的列数。 使用 ncols 时,你必须只传递一个未嵌套的绘图列表(而不是一个嵌套的绘图列表)。

  • width (int, optional) – 您希望所有图表的宽度

  • height (int, optional) – 您希望所有图表的高度。

  • toolbar_options (dict, optional) – 一个选项字典,将用于构建网格的工具栏(一个Toolbar的实例)。如果没有提供,将使用Toolbar的默认值。

  • merge_tools (True, False) – 将所有子图中的工具合并到一个工具栏中。

Return type:

GridPlot

示例

>>> gridplot([[plot_1, plot_2], [plot_3, plot_4]])
>>> gridplot([plot_1, plot_2, plot_3, plot_4], ncols=2, width=200, height=100)
>>> gridplot(
        children=[[plot_1, plot_2], [None, plot_3]],
        toolbar_location='right'
        sizing_mode='fixed',
        toolbar_options=dict(logo='gray')
    )

布局#

layout(*args: UIElement, children: list[UIElement] | None = None, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, **kwargs: Any) Column[源代码]#

创建一个基于网格的Bokeh布局对象排列。

Parameters:
  • children (LayoutDOM 的列表的列表) – 用于网格布局的实例列表的列表。可以是以下任意一种 - Plot, Widget, Row, Column, Spacer.

  • sizing_mode ("fixed", "stretch_both", "scale_width", "scale_height", "scale_both") – 布局中的项目如何调整大小以填充可用空间。默认值为 "fixed"。有关不同模式的更多信息,请参阅 sizing_modeLayoutDOM 上的描述。

Returns:

一列Row布局的子元素,所有子元素具有相同的sizing_mode。

Return type:

Column

示例

>>> layout([[plot_1, plot_2], [plot_3, plot_4]])
>>> layout(
        children=[
            [widget_1, plot_1],
            [slider],
            [widget_2, plot_2, plot_3]
        ],
        sizing_mode='fixed',
    )

#

row(children: list[UIElement], *, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, **kwargs: Any) Row[source]#
row(*children: UIElement, sizing_mode: Literal['stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both', 'fixed', 'inherit'] | None = None, **kwargs: Any) Row

创建一行Bokeh布局对象。强制所有对象具有相同的sizing_mode,这是复杂布局工作所必需的。

Parameters:
  • children (LayoutDOM 的列表) – 行的实例列表。可以是以下任意一种 - Plot, Widget, Row, Column, Spacer.

  • sizing_mode ("fixed", "stretch_both", "scale_width", "scale_height", "scale_both") – 布局中的项目如何调整大小以填充可用空间。默认值为 "fixed"。有关不同模式的更多信息,请参阅 sizing_modeLayoutDOM 上的描述。

Returns:

一行具有相同sizing_mode的LayoutDOM对象。

Return type:

Row

示例

>>> row(plot1, plot2)
>>> row(children=[widgets, plot], sizing_mode='stretch_both')

间隔#

class Spacer(*args: Any, id: ID | None = None, **kwargs: Any)[source]

用于填充行或列中空位的空间容器。