Bqplot Documentation: Release 0.10.0
Bqplot Documentation: Release 0.10.0
Bqplot Documentation: Release 0.10.0
Release 0.10.0
Bloomberg LP
1 Introduction 1
1.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Usage 3
2.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
i
ii
CHAPTER 1
Introduction
bqplot is a Grammar of Graphics-based interactive plotting framework for the Jupyter notebook.
In bqplot, every single attribute of the plot is an interactive widget. This allows the user to integrate any plot with
IPython widgets to create a complex and feature rich GUI from just a few simple lines of Python code.
1.1 Goals
1.2 Installation
Using pip:
Using conda
1
bqplot Documentation, Release 0.10.0
2 Chapter 1. Introduction
CHAPTER 2
Usage
2.1 Examples
size = 20
np.random.seed(0)
x_data = np.arange(size)
x_ord = OrdinalScale()
y_sc = LinearScale()
3
bqplot Documentation, Release 0.10.0
[ widget ]
4 Chapter 2. Usage
CHAPTER 3
Each plot starts with a Figure object. A Figure has a number of Axis objects (representing scales) and a number
of Mark objects. Mark objects are a visual representation of the data. Scales transform data into visual properties
(typically a number of pixels, a color, etc.).
x_data = range(10)
y_data = [i ** 2 for i in x_data]
x_sc = LinearScale()
y_sc = LinearScale()
line = Lines(x=x_data,
y=y_data,
scales={'x': x_sc, 'y': y_sc},
colors=['red', 'yellow'])
display(fig)
3.1.1 Figure
5
bqplot Documentation, Release 0.10.0
bqplot.figure.Figure
class bqplot.figure.Figure(**kwargs)
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
__init__(**kwargs)
Public constructor
Methods
3.1.2 Scales
bqplot.scales.Scale
class bqplot.scales.Scale(**kwargs)
The base scale class.
Scale objects represent a mapping between data (the domain) and a visual quantity (The range).
scale_types
dict (class-level attribute) – A registry of existing scale types.
domain_class
type (default: Float) – traitlet type used to validate values in of the domain of the scale.
reverse
bool (default: False) – whether the scale should be reversed.
allow_padding
bool (default: True) – indicates whether figures are allowed to add data padding to this scale or not.
precedence
int (class-level attribute) – attribute used to determine which scale takes precedence in cases when two or
more scales have the same rtype and dtype.
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.LinearScale
class bqplot.scales.LinearScale(**kwargs)
A linear scale.
An affine mapping from a numerical domain to a numerical range.
min
float or None (default: None) – if not None, min is the minimal value of the domain
max
float or None (default: None) – if not None, max is the maximal value of the domain
rtype
string (class-level attribute) – This attribute should not be modifed. The range type of a linear scale is
numerical.
dtype
type (class-level attribute) – the associated data type / domain type
precedence
int (class-level attribute, default_value=2) – attribute used to determine which scale takes precedence in
cases when two or more scales have the same rtype and dtype. default_value is 2 because for the same
range and domain types, LinearScale should take precedence.
stabilized
bool (default: False) – if set to False, the domain of the scale is tied to the data range if set to True,
the domain of the scale is udpated only when the data range is beyond certain thresholds, given by the
attributes mid_range and min_range.
mid_range
float (default: 0.8) – Proportion of the range that is spanned initially. Used only if stabilized is True.
min_range
float (default: 0.6) – Minimum proportion of the range that should be spanned by the data. If the data span
falls beneath that level, the scale is reset. min_range must be <= mid_range. Used only if stabilized is
True.
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.LogScale
class bqplot.scales.LogScale(**kwargs)
A log scale.
A logarithmic mapping from a numerical domain to a numerical range.
min
float or None (default: None) – if not None, min is the minimal value of the domain
max
float or None (default: None) – if not None, max is the maximal value of the domain
rtype
string (class-level attribute) – This attribute should not be modifed by the user. The range type of a linear
scale is numerical.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.DateScale
class bqplot.scales.DateScale(**kwargs)
A date scale, with customizable formatting.
An affine mapping from dates to a numerical range.
min
Date or None (default: None) – if not None, min is the minimal value of the domain
max
Date (default: None) – if not None, max is the maximal value of the domain
domain_class
type (default: Date) – traitlet type used to validate values in of the domain of the scale.
rtype
string (class-level attribute) – This attribute should not be modifed by the user. The range type of a linear
scale is numerical.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.OrdinalScale
class bqplot.scales.OrdinalScale(**kwargs)
An ordinal scale.
A mapping from a discrete set of values to a numerical range.
domain
list (default: []) – The discrete values mapped by the ordinal scale
rtype
string (class-level attribute) – This attribute should not be modifed by the user. The range type of a linear
scale is numerical.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.ColorScale
class bqplot.scales.ColorScale(**kwargs)
A color scale.
A mapping from numbers to colors. The relation is affine by part.
scale_type
{‘linear’} – scale type
colors
list of colors (default: []) – list of colors
min
float or None (default: None) – if not None, min is the minimal value of the domain
max
float or None (default: None) – if not None, max is the maximal value of the domain
mid
float or None (default: None) – if not None, mid is the value corresponding to the mid color.
scheme
string (default: ‘RdYlGn’) – Colorbrewer color scheme of the color scale.
rtype
string (class-level attribute) – The range type of a color scale is ‘Color’. This should not be modifed.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.DateColorScale
class bqplot.scales.DateColorScale(**kwargs)
A date color scale.
A mapping from dates to a numerical domain.
min
Date or None (default: None) – if not None, min is the minimal value of the domain
max
Date or None (default: None) – if not None, max is the maximal value of the domain
mid
Date or None (default: None) – if not None, mid is the value corresponding to the mid color.
rtype
string (class-level attribute) – This attribute should not be modifed by the user. The range type of a color
scale is ‘Color’.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.OrdinalColorScale
class bqplot.scales.OrdinalColorScale(**kwargs)
An ordinal color scale.
Methods
bqplot.scales.GeoScale
class bqplot.scales.GeoScale(**kwargs)
The base projection scale class for Map marks.
The GeoScale represents a mapping between topographic data and a 2d visual representation.
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.Mercator
class bqplot.scales.Mercator(**kwargs)
A geographical projection scale commonly used for world maps.
The Mercator projection is a cylindrical map projection which ensures that any course of constant bearing is a
straight line.
scale_factor
float (default: 190) – Specifies the scale value for the projection
center
list (default: (0, 60)) – Specifies the longitude and latitude where the map is centered.
rotate
tuple (default: (0, 0)) – Degree of rotation in each axis.
rtype
(Number, Number) (class-level attribute) – This attribute should not be modifed. The range type of a geo
scale is a tuple.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.AlbersUSA
class bqplot.scales.AlbersUSA(**kwargs)
A composite projection of four Albers projections meant specifically for the United States.
scale_factor
float (default: 1200) – Specifies the scale value for the projection
rtype
(Number, Number) (class-level attribute) – This attribute should not be modifed. The range type of a geo
scale is a tuple.
dtype
type (class-level attribute) – the associated data type / domain type
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.Gnomonic
class bqplot.scales.Gnomonic(**kwargs)
A perspective projection which displays great circles as straight lines.
The projection is neither equal-area nor conformal.
scale_factor
float (default: 145) – Specifies the scale value for the projection
center
list (default: (0, 60)) – Specifies the longitude and latitude where the map is centered.
precision
float (default: 0.1) – Specifies the threshold for the projections adaptive resampling to the specified value
in pixels.
clip_angle
float (default: 89.999) – Specifies the clipping circle radius to the specified angle in degrees.
__init__(**kwargs)
Public constructor
Methods
bqplot.scales.Stereographic
class bqplot.scales.Stereographic(**kwargs)
A perspective projection that uses a bijective and smooth map at every point except the projection point.
The projection is not an equal-area projection but it is conformal.
scale_factor
float (default: 250) – Specifies the scale value for the projection
rotate
tuple (default: (96, 0)) – Degree of rotation in each axis.
center
list (default: (0, 60)) – Specifies the longitude and latitude where the map is centered.
precision
float (default: 0.1) – Specifies the threshold for the projections adaptive resampling to the specified value
in pixels.
clip_angle
float (default: 90.) – Specifies the clipping circle radius to the specified angle in degrees.
__init__(**kwargs)
Public constructor
Methods
3.1.3 Marks
bqplot.marks.Mark
class bqplot.marks.Mark(**kwargs)
The base mark class.
Traitlet mark attributes may be decorated with metadata.
Data Attribute Decoration
Data attributes are decorated with the following values:
scaled: bool Indicates whether the considered attribute is a data attribute which must be associated with a scale
in order to be taken into account.
rtype: string Range type of the associated scale.
atype: string Key in bqplot’s axis registry of the recommended axis type to represent this scale. When not
specified, the default is ‘bqplot.Axis’.
display_name
string – Holds a user-friendly name for the trait attribute.
mark_types
dict (class-level attribute) – A registry of existing mark types.
scales
Dict of scales (default: {}) – A dictionary of scales holding scales for each data attribute. - If a mark holds
a scaled attribute named ‘x’, the scales dictionary must have a corresponding scale for the key ‘x’. - The
scale’s range type should be equal to the scaled attribute’s range type (rtype).
scales_metadata
Dict (default: {}) – A dictionary of dictionaries holding metadata on the way scales are used by the mark.
For example, a linear scale may be used to count pixels horizontally or vertically. The content of this
dictionnary may change dynamically. It is an instance-level attribute.
preserve_domain
dict (default: {}) – Indicates if this mark affects the domain(s) of the specified scale(s). The keys of this
dictionary are the same as the ones of the “scales” attribute, and values are boolean. If a key is missing, it
is considered as False.
display_legend
bool (default: False) – Display toggle for the mark legend in the general figure legend
labels
list of unicode strings (default: []) – Labels of the items of the mark. This attribute has different meanings
depending on the type of mark.
apply_clip
bool (default: True) – Indicates whether the items that are beyond the limits of the chart should be clipped.
visible
bool (default: True) – Visibility toggle for the mark.
selected_style
dict (default: {}) – CSS style to be applied to selected items in the mark.
unselected_style
dict (default: {}) – CSS style to be applied to items that are not selected in the mark, when a selection
exists.
selected
list of integers or None (default: None) – Indices of the selected items in the mark.
tooltip
DOMWidget or None (default: None) – Widget to be displayed as tooltip when elements of the scatter are
hovered on
tooltip_style
Dictionary (default: {‘opacity’: 0.9}) – Styles to be applied to the tooltip widget
enable_hover
Bool (default: True) – Boolean attribute to control the hover interaction for the scatter. If this is false, the
on_hover custom mssg is not sent back to the python side
interactions
Dictionary (default: {‘hover’: ‘tooltip’}) – Dictionary listing the different interactions for each mark. The
key is the event which triggers the interaction and the value is the kind of interactions. Keys and values
can only take strings from separate enums for each mark.
tooltip_location
{‘mouse’, ‘center’} (default: ‘mouse’) – Enum specifying the location of the tooltip. ‘mouse’ places the
tooltip at the location of the mouse when the tooltip is activated and ‘center’ places the tooltip at the center
of the figure. If tooltip is linked to a click event, ‘mouse’ places the tooltip at the location of the click that
triggered the tooltip to be visible.
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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.
Continued on next page
bqplot.marks.Lines
class bqplot.marks.Lines(**kwargs)
Lines mark.
In the case of the Lines mark, scales for ‘x’ and ‘y’ MUST be provided.
icon
string (class-level attribute) – Font-awesome icon for the respective mark
name
string (class-level attribute) – User-friendly name of the mark
colors
list of colors (default: CATEGORY10) – List of colors of the Lines. If the list is shorter than the number
of lines, the colors are reused.
close_path
bool (default: False) – Whether to close the paths or not.
fill
{‘none’, ‘bottom’, ‘top’, ‘inside’} – Fill in the area defined by the curves
fill_colors
list of colors (default: []) – Fill colors for the areas. Defaults to stroke-colors when no color provided.
opacities
list of floats (default: []) – Opacity for the lines and patches. Defaults to 1 when the list is too short, or the
element of the list is set to None.
fill_opacities
list of floats (default: []) – Opacity for the areas. Defaults to 1 when the list is too short, or the element of
the list is set to None.
stroke_width
float (default: 2) – Stroke width of the Lines
labels_visibility
{‘none’, ‘label’} – Visibility of the curve labels
curves_subset
list of integers or None (default: []) – If set to None, all the lines are displayed. Otherwise, only the items
in the list will have full opacity, while others will be faded.
line_style
{‘solid’, ‘dashed’, ‘dotted’, ‘dash_dotted’} – Line style.
interpolation
{‘linear’, ‘basis’, ‘cardinal’, ‘monotone’} – Interpolation scheme used for interpolation between the data
points provided. Please refer to the svg interpolate documentation for details about the different interpola-
tion schemes.
marker
{‘circle’, ‘cross’, ‘diamond’, ‘square’, ‘triangle-down’, – ‘triangle-up’, ‘arrow’, ‘rectangle’, ‘ellipse’}
Marker shape
marker_size
nonnegative int (default: 64) – Default marker size in pixels
Data Attributes
x
numpy.ndarray (default: []) – abscissas of the data points (1d or 2d array)
y
numpy.ndarray (default: []) – ordinates of the data points (1d or 2d array)
color
numpy.ndarray (default: None) – colors of the different lines based on data. If it is [], then the colors from
the colors attribute are used. Each line has a single color and if the size of colors is less than the number
of lines, the remaining lines are given the default colors.
Notes
The fields which can be passed to the default tooltip are: name: label of the line index: index of the line
being hovered on color: data attribute for the color of the line
The following are the events which can trigger interactions: click: left click of the mouse hover: mouse-
over an element
The following are the interactions which can be linked to the above events: tooltip: display tooltip
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_background_click(callback[, remove])
on_click(callback[, remove])
on_displayed(callback[, remove]) (Un)Register a widget displayed callback.
on_element_click(callback[, remove])
on_hover(callback[, remove])
on_legend_click(callback[, remove])
on_legend_hover(callback[, remove])
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 con-
structed.
open() Open a comm to the frontend if one isn’t already open.
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.
Continued on next page
bqplot.marks.FlexLine
class bqplot.marks.FlexLine(**kwargs)
Flexible Lines mark.
In the case of the FlexLines mark, scales for ‘x’ and ‘y’ MUST be provided. Scales for the color and width data
attributes are optional. In the case where another data attribute than ‘x’ or ‘y’ is provided but the corresponding
scale is missing, the data attribute is ignored.
name
string (class-level attributes) – user-friendly name of the mark
colors
list of colors (default: CATEGORY10) – List of colors for the Lines
stroke_width
float (default: 1.5) – Default stroke width of the Lines
Data Attributes
x
numpy.ndarray (default: []) – abscissas of the data points (1d array)
y
numpy.ndarray (default: []) – ordinates of the data points (1d array)
color
numpy.ndarray or None (default: None) – Array controlling the color of the data points
width
numpy.ndarray or None (default: None) – Array controlling the widths of the Lines.
__init__(**kwargs)
Methods
__init__(**kwargs)
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.
Continued on next page
bqplot.marks.Scatter
class bqplot.marks.Scatter(**kwargs)
Scatter mark.
In the case of the Scatter mark, scales for ‘x’ and ‘y’ MUST be provided. The scales of other data attributes
are optional. In the case where another data attribute than ‘x’ or ‘y’ is provided but the corresponding scale is
color: numpy.ndarray or None (default: None) color of the data points (1d array). Defaults to default_color
when not provided or when a value is NaN
opacity: numpy.ndarray or None (default: None) opacity of the data points (1d array). Defaults to de-
fault_opacity when not provided or when a value is NaN
size: numpy.ndarray or None (default: None) size of the data points. Defaults to default_size when not pro-
vided or when a value is NaN
skew: numpy.ndarray or None (default: None) skewness of the markers representing the data points. De-
faults to default_skew when not provided or when a value is NaN
rotation: numpy.ndarray or None (default: None) orientation of the markers representing the data points.
The rotation scale’s range is [0, 180] Defaults to 0 when not provided or when a value is NaN.
Notes
The fields which can be passed to the default tooltip are: All the data attributes index: index of the marker
being hovered on
The following are the events which can trigger interactions: click: left click of the mouse hover: mouse-
over an element
The following are the interactions which can be linked to the above events: tooltip: display tooltip add:
add new points to the scatter (can only linked to click)
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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.
Continued on next page
bqplot.marks.Hist
class bqplot.marks.Hist(**kwargs)
Histogram mark.
In the case of the Hist mark, scales for ‘sample’ and ‘count’ MUST be provided.
icon
string (class-level attribute) – font-awesome icon for that mark
name
string (class-level attribute) – user-friendly name of the mark
bins
nonnegative int (default: 10) – number of bins in the histogram
normalized
bool (default: False) – Boolean attribute to return normalized values which sum to 1 or direct counts for
the count attribute. The scale of count attribute is determined by the value of this flag.
colors
list of colors (default: CATEGORY10) – List of colors of the Histogram. If the list is shorter than the
number of bins, the colors are reused.
stroke
Color or None (default: None) – Stroke color of the histogram
opacities
list of floats (default: []) – Opacity for the bins of the histogram. Defaults to 1 when the list is too short,
or the element of the list is set to None.
midpoints
list (default: []) – midpoints of the bins of the histogram. It is a read-only attribute.
Data Attributes
sample
numpy.ndarray (default: []) – sample of which the histogram must be computed.
count
numpy.ndarray (read-only) – number of sample points per bin. It is a read-only attribute.
Notes
The fields which can be passed to the default tooltip are: midpoint: mid-point of the bin related to the rect-
angle hovered on count: number of elements in the bin hovered on bin_start: start point of the bin bin-end:
end point of the bin index: index of the bin
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_background_click(callback[, remove])
Continued on next page
bqplot.marks.Bars
class bqplot.marks.Bars(**kwargs)
Bar mark.
In the case of the Bars mark, scales for ‘x’ and ‘y’ MUST be provided. The scales of other data attributes
are optional. In the case where another data attribute than ‘x’ or ‘y’ is provided but the corresponding scale is
missing, the data attribute is ignored.
icon
string (class-level attribute) – font-awesome icon for that mark
name
string (class-level attribute) – user-friendly name of the mark
color_mode
{‘auto’, ‘group’, ‘element’} – enum attribute to specify if color should be the same for all bars with the
same x or for all bars which belong to the same array in Y ‘group’ means for every x all bars have same
color. ‘element’ means for every dimension of y, all bars have same color. ‘auto’ picks ‘group’ and
‘element’ for 1-d and 2-d values of Y respectively.
type
{‘stacked’, ‘grouped’} – whether 2-dimensional bar charts should appear grouped or stacked.
colors
list of colors (default: CATEGORY10) – list of colors for the bars.
orientation
{‘horizontal’, ‘vertical’} – Specifies whether the bar chart is drawn horizontally or vertically. If a horizontal
bar chart is drawn, the x data is drawn vertically.
padding
float (default: 0.05) – attribute to control the spacing between the bars value is specified as a percentage
of the width of the bar
stroke
Color or None (default: None) – stroke color for the bars
opacities
list of floats (default: []) – Opacities for the bars. Defaults to 1 when the list is too short, or the element of
the list is set to None.
base
float (default: 0.0) – reference value from which the bars are drawn. defaults to 0.0
align
{‘center’, ‘left’, ‘right’} – alignment of bars with respect to the tick value
Data Attributes
x
numpy.ndarray (default: []) – abscissas of the data points (1d array)
y
numpy.ndarray (default: []) – ordinates of the values for the data points
color
numpy.ndarray or None (default: None) – color of the data points (1d array). Defaults to default_color
when not provided or when a value is NaN
Notes
The fields which can be passed to the default tooltip are: All the data attributes index: index of the bar being
hovered on sub_index: if data is two dimensional, this is the minor index
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
Continued on next page
bqplot.marks.Graph
class bqplot.marks.Graph(**kwargs)
Graph with nodes and links.
node_data
List – list of node attributes for the graph
link_matrix
numpy.ndarray of shape(len(nodes), len(nodes)) – link data passed as 2d matrix
link_data
List – list of link attributes for the graph
charge
int (default: -300) – charge of force layout. Will be ignored when x and y data attributes are set
link_distance
float (default: 100) – link distance in pixels between nodes. Will be ignored when x and y data attributes
are set
link_type
{‘arc’, ‘line’, ‘slant_line’} (default: ‘arc’) – Enum representing link type
directed
bool (default: True) – directed or undirected graph
highlight_links
bool (default: True) – highlights incoming and outgoing links when hovered on a node
colors
list (default: CATEGORY10) – list of node colors
Data Attributes
x
numpy.ndarray (default: []) – abscissas of the node data points (1d array)
y
numpy.ndarray (default: []) – ordinates of the node data points (1d array)
color
numpy.ndarray or None (default: None) – color of the node data points (1d array).
link_color
numpy.ndarray of shape(len(nodes), len(nodes)) – link data passed as 2d matrix
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager exits
Continued on next page
bqplot.marks.GridHeatMap
class bqplot.marks.GridHeatMap(**kwargs)
GridHeatMap mark.
Alignment: The tiles can be aligned so that the data matches either the start, the end or the midpoints of the tiles.
This is controlled by the align attribute.
Suppose the data passed is a m-by-n matrix. If the scale for the rows is Ordinal, then alignment is by default the
mid points. For a non-ordinal scale, the data cannot be aligned to the mid points of the rectangles.
If it is not ordinal, then two cases arise. If the number of rows passed is m, then align attribute can be used. If
the number of rows passed is m+1, then the data are the boundaries of the m rectangles.
If rows and columns are not passed, and scales for them are also not passed, then ordinal scales are generated
for the rows and columns.
row_align
Enum([‘start’, ‘end’]) – This is only valid if the number of entries in row exactly match the number of
rows in color and the row_scale is not OrdinalScale. start aligns the row values passed to be aligned with
the start of the tiles and end aligns the row values to the end of the tiles.
column_align
Enum([‘start’, end’]) – This is only valid if the number of entries in column exactly match the number of
columns in color and the column_scale is not OrdinalScale. start aligns the column values passed to be
aligned with the start of the tiles and end aligns the column values to the end of the tiles.
anchor_style
dict (default: {‘fill’: ‘white’, ‘stroke’: ‘blue’}) – Controls the style for the element which serves as the
anchor during selection.
Data Attributes
color
numpy.ndarray or None (default: None) – color of the data points (2d array). The number of elements in
this array correspond to the number of cells created in the heatmap.
row
numpy.ndarray or None (default: None) – labels for the rows of the color array passed. The length of this
can be no more than 1 away from the number of rows in color. This is a scaled attribute and can be used to
affect the height of the cells as the entries of row can indicate the start or the end points of the cells. Refer
to the property row_align. If this property is None, then a uniformly spaced grid is generated in the row
direction.
column
numpy.ndarray or None (default: None) – labels for the columns of the color array passed. The length of
this can be no more than 1 away from the number of columns in color This is a scaled attribute and can
be used to affect the width of the cells as the entries of column can indicate the start or the end points of
the cells. Refer to the property column_align. If this property is None, then a uniformly spaced grid is
generated in the column direction.
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager exits
hold_trait_notifications() Context manager for bundling trait change notifications
and cross validation.
Continued on next page
bqplot.marks.HeatMap
class bqplot.marks.HeatMap(**kwargs)
HeatMap mark.
Data Attributes
color
numpy.ndarray or None (default: None) – color of the data points (2d array).
x
numpy.ndarray or None (default: None) – labels for the columns of the color array passed. The length of
this has to be the number of columns in color. This is a scaled attribute.
y
numpy.ndarray or None (default: None) – labels for the rows of the color array passed. The length of this
has to be the number of rows in color. This is a scaled attribute.
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_background_click(callback[, remove])
on_click(callback[, remove])
on_displayed(callback[, remove]) (Un)Register a widget displayed callback.
on_element_click(callback[, remove])
on_hover(callback[, remove])
on_legend_click(callback[, remove])
on_legend_hover(callback[, remove])
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 con-
structed.
open() Open a comm to the frontend if one isn’t already open.
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 at-
tributes.
setup_instance(*args, **kwargs)
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 speci-
fied name.
bqplot.marks.Label
class bqplot.marks.Label(**kwargs)
Label mark.
x_offset
int (default: 0) – horizontal offset in pixels from the stated x location
y_offset
int (default: 0) – vertical offset in pixels from the stated y location
text
string (default: ‘’) – text to be displayed
default_size
string (default: ‘14px’) – font size in px, em or ex
font_weight
{‘bold’, ‘normal’, ‘bolder’} – font weight of the caption
drag_size
nonnegative float (default: 1.) – Ratio of the size of the dragged label font size to the default label font
size.
align
{‘start’, ‘middle’, ‘end’} – alignment of the text with respect to the provided location enable_move: Bool
(default: False) Enable the label to be moved by dragging. Refer to restrict_x, restrict_y for more options.
restrict_x
bool (default: False) – Restricts movement of the label to only along the x axis. This is valid only when
enable_move is set to True. If both restrict_x and restrict_y are set to True, the label cannot be moved.
restrict_y
bool (default: False) – Restricts movement of the label to only along the y axis. This is valid only when
enable_move is set to True. If both restrict_x and restrict_y are set to True, the label cannot be moved.
Data Attributes
x
numpy.ndarray (default: []) – horizontal position of the labels, in data coordinates or in figure coordinates
y
numpy.ndarray (default: []) – vertical position of the labels, in data coordinates or in figure coordinates
color
numpy.ndarray or None (default: None) – label colors
size
numpy.ndarray or None (default: None) – label sizes
rotation
numpy.ndarray or None (default: None) – label rotations
opacity
numpy.ndarray or None (default: None) – label opacities
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_background_click(callback[, remove])
on_click(callback[, remove])
on_displayed(callback[, remove]) (Un)Register a widget displayed callback.
on_drag(callback[, remove])
on_drag_end(callback[, remove])
on_drag_start(callback[, remove])
on_element_click(callback[, remove])
on_hover(callback[, remove])
on_legend_click(callback[, remove])
on_legend_hover(callback[, remove])
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 con-
structed.
open() Open a comm to the frontend if one isn’t already open.
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 at-
tributes.
setup_instance(*args, **kwargs)
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.
Continued on next page
bqplot.marks.OHLC
class bqplot.marks.OHLC(**kwargs)
Open/High/Low/Close marks.
icon
string (class-level attribute) – font-awesome icon for that mark
name
string (class-level attribute) – user-friendly name of the mark
marker
{‘candle’, ‘bar’} – marker type
stroke
color (default: None) – stroke color of the marker
stroke_width
float (default: 1.0) – stroke width of the marker
colors
List of colors (default: [‘limegreen’, ‘red’]) – fill colors for the markers (up/down)
opacities
list of floats (default: []) – Opacities for the markers of the OHLC mark. Defaults to 1 when the list is too
short, or the element of the list is set to None.
format
string (default: ‘ohlc’) – description of y data being passed supports all permutations of the strings ‘ohlc’,
‘oc’, and ‘hl’
Data Attributes
x
numpy.ndarray – abscissas of the data points (1d array)
y
numpy.ndarrays – Open/High/Low/Close ordinates of the data points (2d array)
Notes
The fields which can be passed to the default tooltip are: x: the x value associated with the bar/candle open:
open value for the bar/candle high: high value for the bar/candle low: low value for the bar/candle close:
close value for the bar/candle index: index of the bar/candle being hovered on
__init__(**kwargs)
Methods
__init__(**kwargs)
Continued on next page
bqplot.marks.Pie
class bqplot.marks.Pie(**kwargs)
Piechart mark.
colors
list of colors (default: CATEGORY10) – list of colors for the slices.
stroke
color (default: ‘white’) – stroke color for the marker
opacities
list of floats (default: []) – Opacities for the slices of the Pie mark. Defaults to 1 when the list is too short,
or the element of the list is set to None.
sort
bool (default: False) – sort the pie slices by descending sizes
x
Float (default: 0.5) or Date – horizontal position of the pie center, in data coordinates or in figure coordi-
nates
y
Float (default: 0.5) – vertical y position of the pie center, in data coordinates or in figure coordinates
radius
Float – radius of the pie, in pixels
inner_radius
Float – inner radius of the pie, in pixels
start_angle
Float (default: 0.0) – start angle of the pie (from top), in degrees
end_angle
Float (default: 360.0) – end angle of the pie (from top), in degrees
display_labels
{‘none’, ‘inside’, ‘outside’} (default: ‘inside’) – label display options
display_values
bool (default: False) – if True show values along with labels
values_format
string (default: ‘.2f’) – format for displaying values
label_color
Color or None (default: None) – color of the labels
font_size
string (default: ‘14px’) – label font size in px, em or ex
font_weight
{‘bold’, ‘normal’, ‘bolder’} (default: ‘normal’) – label font weight
Data Attributes
sizes
numpy.ndarray (default: []) – proportions of the pie slices
color
numpy.ndarray or None (default: None) – color of the data points. Defaults to colors when not provided.
Notes
The fields which can be passed to the default tooltip are: : the x value associated with the bar/candle open:
open value for the bar/candle high: high value for the bar/candle low: low value for the bar/candle close:
close value for the bar/candle index: index of the bar/candle being hovered on
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_background_click(callback[, remove])
on_click(callback[, remove])
on_displayed(callback[, remove]) (Un)Register a widget displayed callback.
on_element_click(callback[, remove])
on_hover(callback[, remove])
on_legend_click(callback[, remove])
on_legend_hover(callback[, remove])
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 con-
structed.
open() Open a comm to the frontend if one isn’t already open.
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.
Continued on next page
bqplot.marks.Map
class bqplot.marks.Map(**kwargs)
Map mark.
colors
Dict (default: {}) – default colors for items of the map when no color data is passed. The dictionary should
be indexed by the id of the element and have the corresponding colors as values. The key default_color
controls the items for which no color is specified.
selected_styles
Dict (default: {‘selected_fill’: ‘Red’, ‘selected_stroke’: None, ‘selected_stroke_width’: 2.0}) – Dictionary
containing the styles for selected subunits
hovered_styles
Dict (default: {‘hovered_fill’: ‘Orange’, ‘hovered_stroke’: None, ‘hovered_stroke_width’: 2.0}) – Dictio-
nary containing the styles for hovered subunits
selected
List (default: []) – list containing the selected countries in the map
hover_highlight
bool (default: True) – boolean to control if the map should be aware of which country is being hovered on.
map_data
tuple (default: topoload(“WorldMapData.json”)) – tuple containing which map is to be displayed
Data Attributes
color
Dict or None (default: None) – dictionary containing the data associated with every country for the color
scale
__init__(**kwargs)
Methods
__init__(**kwargs)
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.
Continued on next page
3.1.4 Axes
bqplot.axes.Axis
class bqplot.axes.Axis(**kwargs)
A line axis.
A line axis is the visual representation of a numerical or date scale.
icon
string (class-level attribute) – The font-awesome icon name for this object.
axis_types
dict (class-level attribute) – A registry of existing axis types.
orientation
{‘horizontal’, ‘vertical’} – The orientation of the axis, either vertical or horizontal
side
{‘bottom’, ‘top’, ‘left’, ‘right’} or None (default: None) – The side of the axis, either bottom, top, left or
right.
label
string (default: ‘’) – The axis label
tick_format
string or None (default: ‘’) – The tick format for the axis, for dates use d3 string formatting.
scale
Scale – The scale represented by the axis
num_ticks
int or None (default: None) – If tick_values is None, number of ticks
tick_values
numpy.ndarray or None (default: None) – Tick values for the axis
offset
dict (default: {}) – Contains a scale and a value {‘scale’: scale or None, ‘value’: value of the offset} If
offset[‘scale’] is None, the corresponding figure scale is used instead.
label_location
{‘middle’, ‘start’, ‘end’} – The location of the label along the axis, one of ‘start’, ‘end’ or ‘middle’
label_color
Color or None (default: None) – The color of the axis label
grid_lines
{‘none’, ‘solid’, ‘dashed’} – The display of the grid lines
grid_color
Color or None (default: None) – The color of the grid lines
color
Color or None (default: None) – The color of the line
label_offset
string or None (default: None) – Label displacement from the axis line. Units allowed are ‘em’, ‘px’ and
‘ex’. Positive values are away from the figure and negative values are towards the figure with resepect to
the axis line.
visible
bool (default: True) – A visibility toggle for the axis
__init__(**kwargs)
Public constructor
Methods
bqplot.axes.ColorAxis
class bqplot.axes.ColorAxis(**kwargs)
A colorbar axis.
A color axis is the visual representation of a color scale.
scale
ColorScale – The scale represented by the axis
__init__(**kwargs)
Public constructor
Methods
bqplot.market_map.MarketMap
class bqplot.market_map.MarketMap(**kwargs)
Waffle wrapped map.
names
numpy.ndarray of strings (default: []) – The elements can also be objects convertible to string primary key
for the map data. A rectangle is created for each unique entry in this array
groups
numpy.ndarray (default: []) – attribute on which the groupby is run. If this is an empty arrray, then there
is no group by for the map.
display_text
numpy.ndarray or None(default: None) – data to be displayed on each rectangle of the map.If this is empty
it defaults to the names attribute.
ref_data
pandas.DataDrame or None (default: None) – Additional data associated with each element of the map.
The data in this data frame can be displayed as a tooltip.
color
numpy.ndarray (default: []) – Data to represent the color for each of the cells. If the value of the data is
NaN for a cell, then the color of the cell is the color of the group it belongs to in absence of data for color
scales
Dictionary of scales holding a scale for each data attribute – If the map has data being passed as color,
then a corresponding color scale is required
axes
List of axes – Ability to add an axis for the scales which are used to scale data represented in the map
on_hover
custom event – This event is received when the mouse is hovering over a cell. Returns the data of the cell
and the ref_data associated with the cell.
tooltip_widget
Instance of a widget – Widget to be displayed as the tooltip. This can be combined with the on_hover
event to display the chart corresponding to the cell being hovered on.
tooltip_fields
list – names of the fields from the ref_data dataframe which should be displayed in the tooltip.
tooltip_formats
list – formats for each of the fields for the tooltip data. Order should match the order of the tooltip_fields
show_groups
bool – attribute to determine if the groups should be displayed. If set to True, the finer elements are blurred
Map Drawing Attributes
cols
int – Suggestion for no of columns in the map.If not specified, value is inferred from the no of rows and
no of cells
rows
int – No of rows in the map.If not specified, value is inferred from the no of cells and no of columns. If
both rows and columns are not specified, then a square is constructed basing on the no of cells. The above
two attributes are suggestions which are respected unless they are not feasible. One required condition is
that, the number of columns is odd when row_groups is greater than 1.
row_groups
int – No of groups the rows should be divided into. This can be used to draw more square cells for each of
the groups
Layout Attributes
map_margin
dict (default: {top=50, bottom=50, left=50, right=50}) – 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
Display Attributes
colors: list of colors Colors for each of the groups which are cycled over to cover all the groups
title: string Title of the Market Map
title_style: dict CSS style for the title of the Market Map
stroke: color Stroke of each of the cells of the market map
group_stroke: color Stroke of the border for the group of cells corresponding to a group
selected_stroke: color stroke for the selected cells
hovered_stroke: color stroke for the cell being hovered on
font_style: dict CSS style for the text of each cell
Other Attributes
enable_select: bool boolean to control the ability to select the cells of the map by clicking
enable_hover: bool boolean to control if the map should be aware of which cell is being hovered on. If it is set
to False, tooltip will not be displayed
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager 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_hover(callback[, remove])
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.
Continued on next page
bqplot.market_map.SquareMarketMap
class bqplot.market_map.SquareMarketMap(**kwargs)
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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 man-
ager exits
Continued on next page
3.1.6 Interacts
bqplot.interacts.BrushIntervalSelector
class bqplot.interacts.BrushIntervalSelector(**kwargs)
Brush interval selector interaction.
This 1-D selector interaction enables the user to select an interval using the brushing action of the mouse. A
mouse-down marks the start of the interval. The drag after the mouse down in the x-direction selects the extent
Methods
bqplot.interacts.BrushSelector
class bqplot.interacts.BrushSelector(**kwargs)
Brush interval selector interaction.
This 2-D selector interaction enables the user to select a rectangular region using the brushing action of the
mouse. A mouse-down marks the starting point of the interval. The drag after the mouse down selects the
rectangle of interest and a mouse-up signifies the end point of the interval.
Once an interval is drawn, the selector can be moved to a new interval by dragging the selector to the new
interval.
A double click at the same point without moving the mouse will result in the entire interval being selected.
selected
numpy.ndarray – Two element array containing the start and end of the interval selected in terms
of the scales of the selector. This attribute changes while the selection is being made with the
BrushIntervalSelector.
brushing
bool (default: False) – boolean attribute to indicate if the selector is being dragged. It is True when the
selector is being moved and False when it is not. This attribute can be used to trigger computationally
intensive code which should be run only on the interval selection being completed as opposed to code
which should be run whenever selected is changing.
color
Color or None (default: None) – Color of the rectangle representing the brush selector.
__init__(**kwargs)
Methods
__init__(**kwargs)
Continued on next page
bqplot.interacts.HandDraw
class bqplot.interacts.HandDraw(**kwargs)
A hand-draw interaction.
This can be used to edit the ‘y’ value of an existing line using the mouse. The minimum and maximum x values
of the line which can be edited may be passed as parameters. The y-values for any part of the line can be edited
by drawing the desired path while holding the mouse-down. y-values corresponding to x-values smaller than
min_x or greater than max_x cannot be edited by HandDraw.
lines
an instance Lines mark or None (default: None) – The instance of Lines which is edited using the hand-
draw interaction. The ‘y’ values of the line are changed according to the path of the mouse. If the lines
has multi dimensional ‘y’, then the ‘line_index’ attribute is used to selected the ‘y’ to be edited.
line_index
nonnegative integer (default: 0) – For a line with multi-dimensional ‘y’, this indicates the index of the ‘y’
to be edited by the handdraw.
min_x
float or Date or None (default: None) – The minimum value of ‘x’ which should be edited via the hand-
draw.
max_x
float or Date or None (default: None) – The maximum value of ‘x’ which should be edited via the hand-
draw.
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.IndexSelector
class bqplot.interacts.IndexSelector(**kwargs)
Index selector interaction.
This 1-D selector interaction uses the mouse x-cooridnate to select the corresponding point in terms of the
selector scale.
Index Selector has two modes:
1. default mode: The mouse controls the x-position of the selector.
2. frozen mode: In this mode, the selector is frozen at a point and does not respond to mouse
events.
A single click switches between the two modes.
selected
numpy.ndarray – A single element array containing the point corresponding the x-position of the mouse.
This attribute is updated as you move the mouse along the x-direction on the figure.
color
Color or None (default: None) – Color of the line representing the index selector.
line_width
nonnegative integer (default: 0) – Width of the line represetning the index selector.
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.FastIntervalSelector
class bqplot.interacts.FastIntervalSelector(**kwargs)
Fast interval selector interaction.
This 1-D selector is used to select an interval on the x-scale by just moving the mouse (without clicking or
dragging). The x-coordinate of the mouse controls the mid point of the interval selected while the y-coordinate
of the mouse controls the the width of the interval. The larger the y-coordinate, the wider the interval selected.
Interval selector has three modes:
1. default mode: This is the default mode in which the mouse controls the location and width of the
interval.
2. fixed-width mode: In this mode the width of the interval is frozen and only the location of the in-
terval is controlled with the mouse. A single click from the default mode takes you to this mode.
Another single click takes you back to the default mode.
3. frozen mode: In this mode the selected interval is frozen and the selector does not respond to
mouse move. A double click from the default mode takes you to this mode. Another double
click takes you back to the default mode.
selected
numpy.ndarray – Two-element array containing the start and end of the interval selected in terms of the
scale of the selector.
color
Color or None (default: None) – color of the rectangle representing the interval selector
size
Float or None (default: None) – if not None, this is the fixed pixel-width of the interval selector
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.MultiSelector
class bqplot.interacts.MultiSelector(**kwargs)
Multi selector interaction.
This 1-D selector interaction enables the user to select multiple intervals using the mouse. A mouse-down marks
the start of the interval. The drag after the mouse down in the x-direction selects the extent and a mouse-up
signifies the end of the interval.
The current selector is highlighted with a green border and the inactive selectors are highlighted with a red
border.
The multi selector has three modes:
1. default mode: In this mode the interaction behaves exactly as the brush selector interaction with
the current selector.
2. add mode: In this mode a new selector can be added by clicking at a point and dragging over the
interval of interest. Once a new selector has been added, the multi selector is back in the default
mode. From the default mode, ctrl+click switches to the add mode.
3. choose mode: In this mode, any of the existing inactive selectors can be set as the active selector.
When an inactive selector is selected by clicking, the multi selector goes back to the default mode.
From the default mode, shift+click switches to the choose mode.
A double click at the same point without moving the mouse in the x-direction will result in the entire interval
being selected for the current selector.
selected
dict – A dictionary with keys being the names of the intervals and values being the two element arrays
containing the start and end of the interval selected by that particular selector in terms of the scale of the
selector. This is a read-only attribute. This attribute changes while the selection is being made with the
MultiSelectorinteraction.
brushing
bool (default: False) – A boolean attribute to indicate if the selector is being dragged. It is True when
the selector is being moved and false when it is not. This attribute can be used to trigger computationally
intensive code which should be run only on the interval selection being completed as opposed to code
which should be run whenever selected is changing.
names
list – A list of strings indicating the keys of the different intervals. Default values are ‘int1’, ‘int2’, ‘int3’
and so on.
show_names
bool (default: True) – Attribute to indicate if the names of the intervals are to be displayed along with the
interval.
__init__(**kwargs)
Methods
__init__(**kwargs)
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 embed-
ding
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.
hidden_selected_changed(name, selected)
hold_sync() Hold syncing any state until the outermost context man-
ager 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 con-
structed.
open() Open a comm to the frontend if one isn’t already open.
reset()
send(content[, buffers]) Sends a custom msg to the widget model in the front-
end.
Continued on next page
bqplot.interacts.OneDSelector
class bqplot.interacts.OneDSelector(**kwargs)
One-dimensional selector interaction
Base class for all selectors which select data in one dimension, i.e., either the x or the y direction. The scale
attribute should be provided.
scale
An instance of Scale – This is the scale which is used for inversion from the pixels to data co-ordinates.
This scale is used for setting the selected attribute for the selector.
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.Interaction
class bqplot.interacts.Interaction(**kwargs)
The base interaction class.
An interaction is a mouse interaction layer for a figure that requires the capture of all mouse events on the plot
area. A consequence is that one can allow only one interaction at any time on a figure.
An interaction can be associated with features such as selection or manual change of specific mark. Although,
they differ from the so called ‘mark interactions’ in that they do not rely on knowing whether a specific element
of the mark are hovered by the mouse.
types
dict (class-level attribute) representing interaction types – A registry of existing interaction types.
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.PanZoom
class bqplot.interacts.PanZoom(**kwargs)
An interaction to pan and zoom wrt scales.
allow_pan
bool (default: True) – Toggle the ability to pan.
allow_zoom
Methods
bqplot.interacts.Selector
class bqplot.interacts.Selector(**kwargs)
Selector interaction. A selector can be used to select a subset of data
Base class for all the selectors.
marks
list (default: []) – list of marks for which the selected attribute is updated based on the data selected by the
selector.
__init__(**kwargs)
Public constructor
Methods
bqplot.interacts.TwoDSelector
class bqplot.interacts.TwoDSelector(**kwargs)
Two-dimensional selector interaction.
Base class for all selectors which select data in both the x and y dimensions. The attributes ‘x_scale’ and
‘y_scale’ should be provided.
x_scale
An instance of Scale – This is the scale which is used for inversion from the pixels to data co-ordinates in
the x-direction. This scale is used for setting the selected attribute for the selector along with y_scale.
y_scale
An instance of Scale – This is the scale which is used for inversion from the pixels to data co-ordinates in
the y-direction. This scale is used for setting the selected attribute for the selector along with x_scale.
__init__(**kwargs)
Public constructor
Methods
bqplot.traits.Date
Methods
__init__([default_value])
class_init(cls, name) Part of the initialization which may depend on the un-
derlying HasDescriptors class.
default_value_repr()
error(obj, value)
get(obj[, cls])
get_default_value() DEPRECATED: Retrieve the static default value for this
trait.
get_metadata(key[, default]) DEPRECATED: Get a metadata value.
info()
init_default_value(obj) DEPRECATED: Set the static default value for the trait
type.
instance_init(obj)
set(obj, value)
set_metadata(key, value) DEPRECATED: Set a metadata key/value.
tag(**metadata) Sets metadata and returns self.
validate(obj, value)
3.1.8 Toolbar
bqplot.toolbar.Toolbar
class bqplot.toolbar.Toolbar(**kwargs)
Default toolbar for bqplot figures.
The default toolbar provides three buttons:
• A Panzoom toggle button which enables panning and zooming the figure.
• A Save button to save the figure as a png image.
• A Reset button, which resets the figure position to its original state.
When the Panzoom button is toggled to True for the first time, a new instance of PanZoom widget is created.
The created PanZoom widget uses the scales of all the marks that are on the figure at this point. When the
PanZoom widget is toggled to False, the figure retrieves its previous interaction. When the Reset button is
pressed, the PanZoom widget is deleted and the figure scales reset to their initial state. We are back to the case
where the PanZoom widget has never been set.
If new marks are added to the figure after the panzoom button is toggled, and these use new scales, those scales
will not be panned or zoomed, unless the reset button is clicked.
figure
instance of Figure – The figure to which the toolbar will apply.
__init__(**kwargs)
Public constructor
Methods
3.1.9 Pyplot
bqplot.pyplot.figure
bqplot.pyplot.show
bqplot.pyplot.show(key=None, display_toolbar=True)
Shows the current context figure in the output area.
Parameters
• key (hashable, optional) – Any variable that can be used as a key for a dictionary.
• display_toolbar (bool (default: True)) – If True, a toolbar for different
mouse interaction is displayed with the figure.
Raises KeyError – When no context figure is associated with the provided key.
Examples
bqplot.pyplot.axes
bqplot.pyplot.plot
bqplot.pyplot.plot(*args, **kwargs)
Draw lines in the current context figure.
Signature: plot(x, y, **kwargs) or plot(y, **kwargs), depending of the length of the list of positional arguments.
In the case where the x array is not provided.
Parameters
• x (numpy.ndarray or list, 1d or 2d (optional)) – The x-coordinates of
the plotted line. When not provided, the function defaults to numpy.arange(len(y)) x can be
1-dimensional or 2-dimensional.
• y (numpy.ndarray or list, 1d or 2d) – The y-coordinates of the plotted line.
If argument x is 2-dimensional it must also be 2-dimensional.
• marker_str (string) – string representing line_style, marker and color. For e.g. ‘g–o’,
‘sr’ etc
• options (dict (default: {})) – Options for the scales to be created. If a scale
labeled ‘x’ is required for that mark, options[‘x’] contains optional keyword arguments for
the constructor of the corresponding scale type.
bqplot.pyplot.scatter
bqplot.pyplot.scatter(x, y, **kwargs)
Draw a scatter in the current context figure.
Parameters
• x (numpy.ndarray, 1d) – The x-coordinates of the data points.
• y (numpy.ndarray, 1d) – The y-coordinates of the data points.
• options (dict (default: {})) – Options for the scales to be created. If a scale
labeled ‘x’ is required for that mark, options[‘x’] contains optional keyword arguments for
the constructor of the corresponding scale type.
• axes_options (dict (default: {})) – Options for the axes to be created. If
an axis labeled ‘x’ is required for that mark, axes_options[‘x’] contains optional keyword
arguments for the constructor of the corresponding axis type.
bqplot.pyplot.hist
bqplot.pyplot.bar
bqplot.pyplot.bar(x, y, **kwargs)
Draws a bar chart in the current context figure.
Parameters
• x (numpy.ndarray, 1d) – The x-coordinates of the data points.
• y (numpy.ndarray, 1d) – The y-coordinates of the data pints.
• options (dict (default: {})) – Options for the scales to be created. If a scale
labeled ‘x’ is required for that mark, options[‘x’] contains optional keyword arguments for
the constructor of the corresponding scale type.
bqplot.pyplot.ohlc
bqplot.pyplot.ohlc(*args, **kwargs)
Draw OHLC bars or candle bars in the current context figure.
Signature: ohlc(x, y, **kwargs) or ohlc(y, **kwargs), depending of the length of the list of positional arguments.
In the case where the x array is not provided
Parameters
• x (numpy.ndarray or list, 1d (optional)) – The x-coordinates of the plot-
ted line. When not provided, the function defaults to numpy.arange(len(y)).
• y (numpy.ndarray or list, 2d) – The ohlc (open/high/low/close) information. A
two dimensional array. y must have the shape (n, 4).
• options (dict (default: {})) – Options for the scales to be created. If a scale
labeled ‘x’ is required for that mark, options[‘x’] contains optional keyword arguments for
the constructor of the corresponding scale type.
• axes_options (dict (default: {})) – Options for the axes to be created. If
an axis labeled ‘x’ is required for that mark, axes_options[‘x’] contains optional keyword
arguments for the constructor of the corresponding axis type.
bqplot.pyplot.geo
bqplot.pyplot.geo(map_data, **kwargs)
Draw a map in the current context figure.
Parameters
• map_data (string or bqplot.map (default: WorldMap)) – Name of the
map or json file required for the map data.
• options (dict (default: {})) – Options for the scales to be created. If a scale
labeled ‘x’ is required for that mark, options[‘x’] contains optional keyword arguments for
the constructor of the corresponding scale type.
• axes_options (dict (default: {})) – Options for the axes to be created. If
an axis labeled ‘x’ is required for that mark, axes_options[‘x’] contains optional keyword
arguments for the constructor of the corresponding axis type.
bqplot.pyplot.clear
bqplot.pyplot.clear()
Clears the current context figure of all marks axes and grid lines.
bqplot.pyplot.close
bqplot.pyplot.close(key)
Closes and unregister the context figure corresponding to the key.
Parameters key (hashable) – Any variable that can be used as a key for a dictionary
bqplot.pyplot.current_figure
bqplot.pyplot.current_figure()
Returns the current context figure.
bqplot.pyplot.scales
bqplot.pyplot.scales(key=None, scales={})
Creates and switches between context scales.
If no key is provided, a new blank context is created.
If a key is provided for which a context already exists, the existing context is set as the current context.
If a key is provided and no corresponding context exists, a new context is created for that key and set as the
current context.
Parameters
• key (hashable, optional) – Any variable that can be used as a key for a dictionary
• scales (dictionary) – Dictionary of scales to be used in the new context
Example
>>> scales(scales={
>>> 'x': Keep,
>>> 'color': ColorScale(min=0, max=1)
>>> })
This creates a new scales context, where the ‘x’ scale is kept from the previous context, the ‘color’ scale is an
instance of ColorScale provided by the user. Other scales, potentially needed such as the ‘y’ scale in the case of
a line chart will be created on the fly when needed.
Notes
bqplot.pyplot.xlim
bqplot.pyplot.xlim(min, max)
Set the domain bounds of the current ‘x’ scale.
bqplot.pyplot.ylim
bqplot.pyplot.ylim(min, max)
Set the domain bounds of the current ‘y’ scale.
bqplot.pyplot.xlabel
bqplot.pyplot.ylabel
b
bqplot, 5
bqplot.axes, 53
bqplot.figure, 5
bqplot.interacts, 61
bqplot.market_map, 57
bqplot.marks, 26
bqplot.pyplot, 80
bqplot.scales, 8
bqplot.toolbar, 78
bqplot.traits, 77
87
bqplot Documentation, Release 0.10.0
89
bqplot Documentation, Release 0.10.0
90 Index
bqplot Documentation, Release 0.10.0
Index 91
bqplot Documentation, Release 0.10.0
92 Index
bqplot Documentation, Release 0.10.0
U
unselected_style (bqplot.marks.Mark attribute), 28
V
values_format (bqplot.marks.Pie attribute), 50
visible (bqplot.axes.Axis attribute), 54
visible (bqplot.marks.Mark attribute), 27
W
width (bqplot.marks.FlexLine attribute), 32
X
x (bqplot.marks.Bars attribute), 39
x (bqplot.marks.FlexLine attribute), 32
x (bqplot.marks.Graph attribute), 41
x (bqplot.marks.HeatMap attribute), 44
x (bqplot.marks.Label attribute), 46
x (bqplot.marks.Lines attribute), 30
x (bqplot.marks.OHLC attribute), 48
x (bqplot.marks.Pie attribute), 50
x_offset (bqplot.marks.Label attribute), 46
x_scale (bqplot.interacts.TwoDSelector attribute), 76
xlabel() (in module bqplot.pyplot), 85
Index 93