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

string (default: ‘’) – title of the figure

axes

List of Axes (default: []) – list containing the instances of the axes for the figure

marks

List of Marks (default: []) – list containing the marks which are to be appended to the figure

interaction

Interaction or None (default: None) – optional interaction layer for the figure

scale_x

Scale – Scale representing the x values of the figure

scale_y

Scale – Scale representing the y values of the figure

padding_x

Float (default: 0.0) – Padding to be applied in the horizontal direction of the figure around the data points, proportion of the horizontal length

padding_y

Float (default: 0.025) – Padding to be applied in the vertical direction of the figure around the data points, proportion of the vertical length

legend_location

{‘top-right’, ‘top’, ‘top-left’, ‘left’, ‘bottom-left’, ‘bottom’, ‘bottom-right’, ‘right’} – location of the legend relative to the center of the figure

background_style

Dict (default: {}) – CSS style to be applied to the background of the figure

legend_style

Dict (default: {}) – CSS style to be applied to the SVG legend e.g, {‘fill’: ‘white’}

legend_text

Dict (default: {}) – CSS style to be applied to the legend text e.g., {‘font-size’: 20}

title_style

Dict (default: {}) – CSS style to be applied to the title of the figure

animation_duration

nonnegative int (default: 0) – Duration of transition on change of data attributes, in milliseconds.

Layout Attributes
fig_margin

dict (default: {top=60, bottom=60, left=60, right=60}) – 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.

min_aspect_ratio

float – minimum width / height ratio of the figure

max_aspect_ratio

float – maximum width / height ratio of the figure

save_png:

Saves the figure as a png 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([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(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() 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])
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