plots#

Models for representing top-level plot objects.

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

Collection of plots and other layoutables on arranged on a rectangular grid.

children#

A list of subplots with their associated position in the grid, row and column index and optional row and column spans (the default span is 1).

toolbar#

The toolbar associated with this grid plot, which holds all the tools. It is automatically created with the plot if necessary.

toolbar_location#

Indicates where the layout the toolbar will be located. If set to None, no toolbar will be attached to the grid plot.

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

Model representing a plot, containing glyphs, guides, annotations.

add_glyph(glyph: Glyph, **kwargs: Any) GlyphRenderer[source]#
add_glyph(source: ColumnarDataSource, glyph: Glyph, **kwargs: Any) GlyphRenderer

Adds a glyph to the plot with associated data sources and ranges.

This function will take care of creating and configuring a Glyph object, and then add it to the plot’s list of renderers.

Parameters:
  • source (DataSource) – a data source for the glyphs to all use

  • glyph (Glyph) – the glyph to add to the Plot

Keyword Arguments:
  • the (Any additional keyword arguments are passed on as-is to)

  • initializer. (Glyph)

Returns:

GlyphRenderer

add_layout(obj: Renderer | StyledElement, place: Literal['above', 'below', 'left', 'right', 'center'] = 'center') None[source]#

Adds an object to the plot in the specified place.

If the renderer is already a part of a plot, this operation will move it to the new location. If you need finer control than this, you can manipulate left, right, above, below or center Plot’s properties manually.

Parameters:
  • obj (Renderer) – the object to add to the Plot

  • place (str, optional) – where to add the object (default: ‘center’) Valid places are: ‘left’, ‘right’, ‘above’, ‘below’, ‘center’.

Returns:

None

add_tile(tile_source: TileSource | xyzservices.TileProvider | str, retina: bool = False, **kwargs: Any) TileRenderer[source]#

Adds new TileRenderer into Plot.renderers

Parameters:
Keyword Arguments:

renderer (Additional keyword arguments are passed on as-is to the tile)

Returns:

TileRenderer

Return type:

TileRenderer

add_tools(*tools: Tool | str) None[source]#

Adds tools to the plot.

Parameters:

*tools (Tool) – the tools to add to the Plot

Returns:

None

column(col, gridplot)[source]#

Return whether this plot is in a given column of a GridPlot.

Parameters:
  • col (int) – index of the column to test

  • gridplot (GridPlot) – the GridPlot to check

Returns:

bool

hold(*, render: bool) Generator[None, None, None][source]#

Takes care of turning a property on and off within a scope.

Parameters:

render (bool) – Turns the property hold_render on and off.

remove_tools(*tools: Tool) None[source]#

Removes tools from the plot.

Parameters:

*tools (Tool) – the tools to remove from the Plot

Returns:

None

row(row, gridplot)[source]#

Return whether this plot is in a given row of a GridPlot.

Parameters:
  • row (int) – index of the row to test

  • gridplot (GridPlot) – the GridPlot to check

Returns:

bool

select(*args, **kwargs)[source]#

Query this object and all of its references for objects that match the given selector.

There are a few different ways to call the select method. The most general is to supply a JSON-like query dictionary as the single argument or as keyword arguments:

Parameters:

selector (JSON-like) – some sample text

Keyword Arguments:

kwargs – query dict key/values as keyword arguments

Additionally, for compatibility with Model.select, a selector dict may be passed as selector keyword argument, in which case the value of kwargs['selector'] is used for the query.

For convenience, queries on just names can be made by supplying the name string as the single parameter:

Parameters:

name (str) – the name to query on

Also queries on just type can be made simply by supplying the Model subclass as the single parameter:

Parameters:

type (Model) – the type to query on

Returns:

seq[Model]

Examples

# These three are equivalent
p.select(selector={"type": HoverTool})
p.select({"type": HoverTool})
p.select(HoverTool)

# These two are also equivalent
p.select({"name": "mycircle"})
p.select("mycircle")

# Keyword arguments can be supplied in place of selector dict
p.select({"name": "foo", "type": HoverTool})
p.select(name="foo", type=HoverTool)
above#

A list of renderers to occupy the area above of the plot.

aspect_scale#

A value to be given for increased aspect ratio control. This value is added multiplicatively to the calculated value required for match_aspect. aspect_scale is defined as the ratio of width over height of the figure.

For example, a plot with aspect_scale value of 2 will result in a square in data units to be drawn on the screen as a rectangle with a pixel width twice as long as its pixel height.

Note

This setting only takes effect if match_aspect is set to True.

attribution#

Allows to acknowledge or give credit to data, tile, etc. providers.

This can be in either HTML or plain text forms. Renderers, like tile renderers, can provide additional attributions which will be added after attributions provided here.

Note

This feature is experimental and may change in the short term.

property axis#

Splattable list of Axis objects.

background_fill_alpha#

The fill alpha for the plot background style.

background_fill_color#

The fill color for the plot background style.

background_hatch_alpha#

The hatch alpha for the plot background style.

background_hatch_color#

The hatch color for the plot background style.

background_hatch_extra#

The hatch extra for the plot background style.

background_hatch_pattern#

The hatch pattern for the plot background style.

background_hatch_scale#

The hatch scale for the plot background style.

background_hatch_weight#

The hatch weight for the plot background style.

below#

A list of renderers to occupy the area below of the plot.

border_fill_alpha#

The fill alpha for the plot border style.

border_fill_color#

The fill color for the plot border style.

border_hatch_alpha#

The hatch alpha for the plot border style.

border_hatch_color#

The hatch color for the plot border style.

border_hatch_extra#

The hatch extra for the plot border style.

border_hatch_pattern#

The hatch pattern for the plot border style.

border_hatch_scale#

The hatch scale for the plot border style.

border_hatch_weight#

The hatch weight for the plot border style.

border_line_alpha#

The line alpha for the plot border style.

border_line_cap#

The line cap for the plot border style.

border_line_color#

The line color for the plot border style.

border_line_dash#

The line dash for the plot border style.

border_line_dash_offset#

The line dash offset for the plot border style.

border_line_join#

The line join for the plot border style.

border_line_width#

The line width for the plot border style.

center#

A list of renderers to occupy the center area (frame) of the plot.

extra_x_ranges#

Additional named ranges to make available for mapping x-coordinates.

This is useful for adding additional axes.

extra_x_scales#

Additional named scales to make available for mapping x-coordinates.

This is useful for adding additional axes.

Note

This feature is experimental and may change in the short term.

extra_y_ranges#

Additional named ranges to make available for mapping y-coordinates.

This is useful for adding additional axes.

extra_y_scales#

Additional named scales to make available for mapping y-coordinates.

This is useful for adding additional axes.

Note

This feature is experimental and may change in the short term.

frame_align#

Allows to specify which frame edges to align in multiple-plot layouts.

The default is to align all edges, but users can opt-out from alignment of each individual edge or all edges. Note also that other properties may disable alignment of certain edges, especially when using fixed frame size (frame_width and frame_height properties).

frame_height#

The height of a plot frame or the inner height of a plot, excluding any axes, titles, border padding, etc.

frame_width#

The width of a plot frame or the inner width of a plot, excluding any axes, titles, border padding, etc.

property grid#

Splattable list of Grid objects.

hidpi#

Whether to use HiDPI mode when available.

hold_render#

When set to True all requests to repaint the plot will be hold off.

This is useful when periodically updating many glyphs. For example, let’s assume we have 10 lines on a plot, each with its own datasource. We stream to all of them every second in a for loop like so:

for line in lines:
    line.stream(new_points())

The problem with this code is that every stream triggers a re-rendering of the plot. Even tough repainting only on the last stream would produce almost identical visual effect. Especially for lines with many points this becomes computationally expensive and can freeze your browser. Using a convenience method hold, we can control when rendering is initiated like so:

with plot.hold(render=True):
    for line in lines:
        line.stream(new_points())

In this case we render newly appended points only after the last stream.

property hover#

Splattable list of HoverTool objects.

inner_height#

This is the exact height of the plotting canvas, i.e. the height of the actual plot, without toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook).

Note

This is an experimental feature and the API may change in near future.

inner_width#

This is the exact width of the plotting canvas, i.e. the width of the actual plot, without toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook).

Note

This is an experimental feature and the API may change in near future.

left#

A list of renderers to occupy the area to the left of the plot.

property legend#

Splattable list of Legend objects.

lod_factor#

Decimation factor to use when applying level-of-detail mode.

A lod_factor of N means that only every Nth point in the data source will be drawn while interactive events are active. For example, if lod_factor=200 then only every 200th point will be drawn.

The level-of-detail mode is intended to preserve interactive response times on HTML canvas plots when there are a large number of data points.

Note that a possible alternative to level-of-detail mode is using the WebGL output_backend. WebGL rendering may allow very large data sets to remain interactive without any level-of-detail downsampling. When WebGL output is enabled, level-of-detail mode is not used.

lod_interval#

Interval (in ms) during which an interactive tool event will enable level-of-detail downsampling.

If a plot needs to be re-drawn within lod_interval milliseconds of the last interactive event starting, then level-of-detail mode will be activated. Larger values mean the level-of-detail mode will be “easier” to turn on.

lod_threshold#

A number of data points, above which level-of-detail downsampling may be performed by glyph renderers. For example, if lod_threshold=10000 then level-of-detail mode will not be activated if there are fewer than 10000 points in the data source.

Set to None to disable any level-of-detail downsampling at all.

lod_timeout#

Timeout (in ms) for checking whether interactive tool events are still occurring. Once level-of-detail mode is enabled, a check is made every lod_timeout ms. If no interactive tool events have happened, level-of-detail mode is disabled. Larger values mean the level-of-detail mode will be “slower” to turn off.

match_aspect#

Specify the aspect ratio behavior of the plot. Aspect ratio is defined as the ratio of width over height. This property controls whether Bokeh should attempt to match the (width/height) of data space to the (width/height) in pixels of screen space.

Default is False which indicates that the data aspect ratio and the screen aspect ratio vary independently. True indicates that the plot aspect ratio of the axes will match the aspect ratio of the pixel extent the axes. The end result is that a 1x1 area in data space is a square in pixels, and conversely that a 1x1 pixel is a square in data units.

Note

This setting only takes effect when there are two dataranges. This setting only sets the initial plot draw and subsequent resets. It is possible for tools (single axis zoom, unconstrained box zoom) to change the aspect ratio.

Warning

This setting is incompatible with linking dataranges across multiple plots. Doing so may result in undefined behavior.

min_border#

A convenience property to set all all the min_border_X properties to the same value. If an individual border property is explicitly set, it will override min_border.

min_border_bottom#

Minimum size in pixels of the padding region below the bottom of the central plot region.

Note

This is a minimum. The padding region may expand as needed to accommodate titles or axes, etc.

min_border_left#

Minimum size in pixels of the padding region to the left of the central plot region.

Note

This is a minimum. The padding region may expand as needed to accommodate titles or axes, etc.

min_border_right#

Minimum size in pixels of the padding region to the right of the central plot region.

Note

This is a minimum. The padding region may expand as needed to accommodate titles or axes, etc.

min_border_top#

Minimum size in pixels of the padding region above the top of the central plot region.

Note

This is a minimum. The padding region may expand as needed to accommodate titles or axes, etc.

outer_height#

This is the exact height of the layout, i.e. the height of the actual plot, with toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook).

Note

This is an experimental feature and the API may change in near future.

outer_width#

This is the exact width of the layout, i.e. the height of the actual plot, with toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook).

Note

This is an experimental feature and the API may change in near future.

outline_line_alpha#

The line alpha for the plot border outline.

outline_line_cap#

The line cap for the plot border outline.

outline_line_color#

The line color for the plot border outline.

outline_line_dash#

The line dash for the plot border outline.

outline_line_dash_offset#

The line dash offset for the plot border outline.

outline_line_join#

The line join for the plot border outline.

outline_line_width#

The line width for the plot border outline.

output_backend#

Specify the output backend for the plot area. Default is HTML5 Canvas.

Note

When set to webgl, glyphs without a WebGL rendering implementation will fall back to rendering onto 2D canvas.

renderers#

A list of all glyph renderers for this plot.

This property can be manipulated by hand, but the add_glyph is recommended to help make sure all necessary setup is performed.

reset_policy#

How a plot should respond to being reset. By default, the standard actions are to clear any tool state history, return plot ranges to their original values, undo all selections, and emit a Reset event. If customization is desired, this property may be set to "event_only", which will suppress all of the actions except the Reset event.

right#

A list of renderers to occupy the area to the right of the plot.

title#

A title for the plot. Can be a text string or a Title annotation.

title_location#

Where the title will be located. Titles on the left or right side will be rotated.

toolbar#

The toolbar associated with this plot which holds all the tools. It is automatically created with the plot if necessary.

toolbar_inner#

Locate the toolbar inside the frame. Setting this property to True makes most sense with auto-hidden toolbars.

toolbar_location#

Where the toolbar will be located. If set to None, no toolbar will be attached to the plot.

toolbar_sticky#

True. If False, the toolbar will be outside of the axes, titles etc.

Type:

Stick the toolbar to the edge of the plot. Default

property tools: list[Tool]#
window_axis#

An axis to use for windowed auto-ranging when there are data ranges present on the plot. For example, if window_axis is set to the value "x" then any data ranges in the y-dimension will compute their auto-ranged extents using only data inside the range bounds for the x-axis as configured in the current viewport.

If set to “none” (the default) then auto-ranging will use all available data, regardless of viewport.

x_range#

The (default) data range of the horizontal dimension of the plot.

x_scale#

What kind of scale to use to convert x-coordinates in data space into x-coordinates in screen space.

property xaxis#

Splattable list of Axis objects for the x dimension.

property xgrid#

Splattable list of Grid objects for the x dimension.

y_range#

The (default) data range of the vertical dimension of the plot.

y_scale#

What kind of scale to use to convert y-coordinates in data space into y-coordinates in screen space.

property yaxis#

Splattable list of Axis objects for the y dimension.

property ygrid#

Splattable list of Grid objects for the y dimension.