Skip to content

Figure

bqplot.Figure

Bases: DOMWidget

Main canvas for drawing a chart.

The Figure object holds the list of Marks and Axes. It also holds an optional Interaction object that is responsible for figure-level mouse interactions, the "interaction layer".

Besides, the Figure object has two reference scales, for positioning items in an absolute fashion in the figure canvas.

Style Attributes
ATTRIBUTE DESCRIPTION
title

title of the figure

TYPE: string (default: '')

axes

list containing the instances of the axes for the figure

TYPE: List of Axes (default: [])

marks

list containing the marks which are to be appended to the figure

TYPE: List of Marks (default: [])

interaction

optional interaction layer for the figure

TYPE: Interaction or None (default: None)

scale_x

Scale representing the x values of the figure

TYPE: Scale

scale_y

Scale representing the y values of the figure

TYPE: Scale

padding_x

Padding to be applied in the horizontal direction of the figure around the data points, proportion of the horizontal length

TYPE: Float (default: 0.0)

padding_y

Padding to be applied in the vertical direction of the figure around the data points, proportion of the vertical length

TYPE: Float (default: 0.025)

legend_location

'bottom-left', 'bottom', 'bottom-right', 'right'} location of the legend relative to the center of the figure

TYPE: {'top-right', 'top', 'top-left', 'left',

background_style

CSS style to be applied to the background of the figure

TYPE: Dict (default: {})

legend_style

CSS style to be applied to the SVG legend e.g, {'fill': 'white'}

TYPE: Dict (default: {})

legend_text

CSS style to be applied to the legend text e.g., {'font-size': 20}

TYPE: Dict (default: {})

title_style

CSS style to be applied to the title of the figure

TYPE: Dict (default: {})

animation_duration

Duration of transition on change of data attributes, in milliseconds.

TYPE: nonnegative int (default: 0)

Layout Attributes
ATTRIBUTE DESCRIPTION
pixel_ratio

Pixel ratio of the WebGL canvas (2 on retina screens). Set to 1 for better performance, but less crisp edges. If set to None it will use the browser's window.devicePixelRatio.

display_toolbar

Show or hide the integrated toolbar.

TYPE: boolean (default: True)

fig_margin

Dictionary containing the top, bottom, left and right margins. The user is responsible for making sure that the width and height are greater than the sum of the margins.

TYPE: dict (default: {top=60, bottom=60, left=60, right=60})

auto_layout

Whether to use the auto-layout solver or not

TYPE: boolean (default: False)

min_aspect_ratio

Minimum width / height ratio of the figure

TYPE: float

max_aspect_ratio

Maximum width / height ratio of the figure

TYPE: float

!!! Note

The aspect ratios stand for width / height ratios.

  • If the available space is within bounds in terms of min and max aspect ratio, we use the entire available space.
  • If the available space is too oblong horizontally, we use the client height and the width that corresponds max_aspect_ratio (maximize width under the constraints).
  • If the available space is too oblong vertically, we use the client width and the height that corresponds to min_aspect_ratio (maximize height under the constraint). This corresponds to maximizing the area under the constraints.

Default min and max aspect ratio are both equal to 16 / 9.

get_png_data(callback, scale=None)

Gets the Figure as a PNG memory view

PARAMETER DESCRIPTION
callback

Called with the PNG data as the only positional argument.

scale

Scale up the png resolution when scale > 1, when not given base this on the screen pixel ratio.

DEFAULT: None

save_png(filename='bqplot.png', scale=None)

Saves the Figure as a PNG file

PARAMETER DESCRIPTION
filename

name of the saved file

DEFAULT: 'bqplot.png'

scale

Scale up the png resolution when scale > 1, when not given base this on the screen pixel ratio.

DEFAULT: None

save_svg(filename='bqplot.svg')

Saves the Figure as an SVG file

PARAMETER DESCRIPTION
filename

name of the saved file

DEFAULT: 'bqplot.svg'