bqplot.figure.Figure

class bqplot.figure.Figure(**kwargs)[source]

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.

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
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})
min_aspect_ratio

minimum width / height ratio of the figure

Type:float
max_aspect_ratio

maximum width / height ratio of the figure

Type:float
save_png:

Saves the figure as a PNG file

save_svg:

Saves the figure as an SVG file

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.

__init__(**kwargs)

Public constructor

Methods

__init__(**kwargs) Public constructor
add_class(className) Adds a class to the top level element of the widget.
add_traits(**traits) Dynamically add trait attributes to the Widget.
class_own_trait_events(name) Get a dict of all event handlers defined on this class, not a parent.
class_own_traits(**metadata) Get a dict of all the traitlets defined on this class, not a parent.
class_trait_names(**metadata) Get a list of all the names of this class’ traits.
class_traits(**metadata) Get a dict of all the traits of this class.
close() Close method.
close_all()
get_manager_state([drop_defaults, widgets]) Returns the full state for a widget manager for embedding
get_state([key, drop_defaults]) Gets the widget state, or a piece of it.
get_view_spec()
handle_comm_opened(comm, msg) Static method, called when a widget is constructed.
has_trait(name) Returns True if the object has a trait with the specified name.
hold_sync() Hold syncing any state until the outermost context manager exits
hold_trait_notifications() Context manager for bundling trait change notifications and cross validation.
notify_change(change) Called when a property has changed.
observe(handler[, names, type]) Setup a handler to be called when a trait changes.
on_displayed(callback[, remove]) (Un)Register a widget displayed callback.
on_msg(callback[, remove]) (Un)Register a custom msg receive callback.
on_trait_change([handler, name, remove]) DEPRECATED: Setup a handler to be called when a trait changes.
on_widget_constructed(callback) Registers a callback to be called when a widget is constructed.
open() Open a comm to the frontend if one isn’t already open.
remove_class(className) Removes a class from the top level element of the widget.
save_png([filename]) Saves the Figure as a PNG file
save_svg([filename]) Saves the Figure as an SVG file
send(content[, buffers]) Sends a custom msg to the widget model in the front-end.
send_state([key]) Sends the widget state, or a piece of it, to the front-end, if it exists.
set_state(sync_data) Called when a state is received from the front-end.
set_trait(name, value) Forcibly sets trait attribute, including read-only attributes.
setup_instance(*args, **kwargs) This is called before self.__init__ is called.
trait_events([name]) Get a dict of all the event handlers of this class.
trait_metadata(traitname, key[, default]) Get metadata values for trait by key.
trait_names(**metadata) Get a list of all the names of this class’ traits.
traits(**metadata) Get a dict of all the traits of this class.
unobserve(handler[, names, type]) Remove a trait change handler.
unobserve_all([name]) Remove trait change handlers of any type for the specified name.

Attributes

animation_duration An int trait.
axes An instance of a Python list.
background_style An instance of a Python dict.
comm A trait whose value must be an instance of a specified class.
cross_validation_lock A contextmanager for running a block with our cross validation lock set to True.
fig_margin An instance of a Python dict.
interaction A trait whose value must be an instance of a specified class.
keys An instance of a Python list.
layout
legend_location An enum whose value must be in a given sequence.
legend_style An instance of a Python dict.
legend_text An instance of a Python dict.
log A trait whose value must be an instance of a specified class.
marks An instance of a Python list.
max_aspect_ratio A float trait.
min_aspect_ratio A float trait.
model_id Gets the model id of this widget.
padding_x A float trait.
padding_y A float trait.
scale_x A trait whose value must be an instance of a specified class.
scale_y A trait whose value must be an instance of a specified class.
title A trait for unicode strings.
title_style An instance of a Python dict.
widget_types
widgets