bokeh.charts Interface

Chart Functions

Bar(data, label=None, values=None, color=None, stack=None, group=None, agg='sum', xscale='categorical', yscale='linear', xgrid=False, ygrid=True, continuous_range=None, **kw)

Create a Bar chart using BarBuilder render the geometry from values, cat and stacked.

Parameters:
  • values (iterable) – iterable 2d representing the data series values matrix.
  • cat (list or bool, optional) – list of string representing the categories. (Defaults to None)
  • stacked (bool, optional) – to see the bars stacked or grouped. (Defaults to False, so grouping is assumed)
  • continuous_range (Range1d, optional) – Custom continuous_range to be used. (Defaults to None)

In addition the the parameters specific to this chart, userguide_charts_generic_arguments are also accepted as keyword parameters.

Returns:class:Chart <bokeh.charts.Chart>
Return type:a new

Examples

from collections import OrderedDict
from bokeh.charts import Bar, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
xyvalues = OrderedDict()
xyvalues['python']=[-2, 5]
xyvalues['pypy']=[12, 40]
xyvalues['jython']=[22, 30]

cat = ['1st', '2nd']

bar = Bar(xyvalues, cat, title="Stacked bars",
        xlabel="category", ylabel="language")

output_file("stacked_bar.html")
show(bar)

Error

Unable to generate Bokeh plot at /home/travis/build/bokeh/bokeh/sphinx/source/docs/reference/charts.rst:31:

BoxPlot(data, label=None, values=None, color=None, group=None, xscale='categorical', yscale='linear', xgrid=False, ygrid=True, continuous_range=None, **kw)

Generate a box plot from table-like and column-like inputs.

Histogram(data, values=None, label=None, color=None, agg='count', bins=None, yscale='linear', xgrid=False, ygrid=True, continuous_range=None, **kw)
Line(data=None, x=None, y=None, **kws)

Create a line chart using LineBuilder to render the geometry from values and index.

Parameters:
  • values (iterable) – iterable 2d representing the data series values matrix.
  • index (str|1d iterable, optional) – can be used to specify a common custom index for all data series as an 1d iterable of any sort that will be used as series common index or a string that corresponds to the key of the mapping to be used as index (and not as data series) if area.values is a mapping (like a dict, an OrderedDict or a pandas DataFrame)

In addition the the parameters specific to this chart, userguide_charts_generic_arguments are also accepted as keyword parameters.

Returns:class:Chart <bokeh.charts.Chart>
Return type:a new

Examples:

import numpy as np
from bokeh.charts import Line, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
xyvalues = np.array([[2, 3, 7, 5, 26], [12, 33, 47, 15, 126], [22, 43, 10, 25, 26]])

line = Line(xyvalues, title="line", legend="top_left", ylabel='Languages')

output_file('line.html')
show(line)

Error

Unable to generate Bokeh plot at /home/travis/build/bokeh/bokeh/sphinx/source/docs/reference/charts.rst:29:

If using all scalar values, you must pass an index

Scatter(data=None, x=None, y=None, **kws)

Create a scatter chart using ScatterBuilder to render the geometry from values.

Parameters:data (arrays or dict(array) or list(dict) or pd.DataFrame) – table-like data

In addition the the parameters specific to this chart, userguide_charts_generic_arguments are also accepted as keyword parameters.

Returns:class:Chart <bokeh.charts.Chart>
Return type:a new

Examples:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Scatter, output_file, show

scatter = Scatter(df, x='mpg', y='hp', color='cyl', marker='origin',
                  title="mpg", xlabel="Miles Per Gallon", ylabel="Horsepower")

output_file('scatter.html')
show(scatter)

Helper Classes

class Chart(*args, **kwargs)

The main Chart class, the core of the Bokeh.charts interface.

add_builder(builder)
add_labels(dim, label)
add_legend(legends)

Add the legend to your plot, and the plot to a new Document.

It also add the Document to a new Session in the case of server output.

Parameters:legends (List(Tuple(String, List(GlyphRenderer)) – A list of tuples that maps text labels to the legend to corresponding renderers that should draw sample representations for those labels.
add_ranges(dim, range)
add_renderers(builder, renderers)
add_scales(dim, scale)
create_axes()
create_grids(xgrid=True, ygrid=True)
create_tools(tools)

Create tools if given tools=True input.

Only adds tools if given boolean and does not already have tools added to self.

filename(value)

Chained method for filename option.

get_class(view_model_name)

Given a __view_model__ name, returns the corresponding class object

height(value)

Chained method for height option.

id(value)

Chained method for id option.

legend(value)

Chained method for legend option.

make_axis(dim, location, scale, label)

Create linear, date or categorical axis depending on the location, scale and with the proper labels.

Parameters:
  • location (str) – the space localization of the axis. It can be left, right, above or below.
  • scale (str) – the scale on the axis. It can be linear, datetime or categorical.
  • label (str) – the label on the axis.
Returns:

Axis instance

Return type:

axis

make_grid(dimension, ticker)

Create the grid just passing the axis and dimension.

Parameters:
  • dimension (int) – the dimension of the axis, ie. xaxis=0, yaxis=1.
  • ticker (obj) – the axis.ticker object
Returns:

Grid instance

Return type:

grid

notebook(value)

Chained method for notebook option.

server(value)

Chained method for server option.

show()

Main show function.

It shows the plot in file, server and notebook outputs.

start_plot()

Add the axis, grids and tools

width(value)

Chained method for width option.

xgrid(value)

Chained method for xgrid option.

xlabel(value)

Chained method for xlabel option.

xscale(value)

Chained method for xscale option.

ygrid(value)

Chained method for ygrid option.

ylabel(value)

Chained method for ylabel option.

yscale(value)

Chained method for yscale option.

Builders

class BarBuilder(*args, **kws)

This is the Bar class and it is in charge of plotting Bar chart (grouped and stacked) in an easy and intuitive way.

Essentially, it provides a way to ingest the data, make the proper calculations and push the references into a source object. We additionally make calculations for the ranges. And finally add the needed glyphs (rects) taking the references from the source.

The x_range is categorical, and is made either from the cat argument or from the indexes of the passed values if no cat is supplied. The y_range can be supplied as the parameter continuous_range, or will be calculated as a linear range (Range1d) based on the supplied values using the following rules:

  • with all positive data: start = 0, end = 1.1 * max
  • with all negative data: start = 1.1 * min, end = 0
  • with mixed sign data: start = 1.1 * min, end = 1.1 * max
glyph

alias of BarGlyph

collect_glyph_kwargs(group)
get_extra_args()
agg

property type: Enum(‘sum’, ‘mean’, ‘count’, ‘nunique’, ‘median’, ‘min’, ‘max’)

bar_width

property type: Float

default_attributes = {'color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1acdfdd0>, 'group': <bokeh.charts._attributes.GroupAttr object at 0x2adf1acdfe50>, 'stack': <bokeh.charts._attributes.GroupAttr object at 0x2adf1acdfe10>, 'label': <bokeh.charts._attributes.GroupAttr object at 0x2adf1acdfd90>}
dimensions = ['values']
fill_alpha

property type: Float

label_attributes = ['stack', 'group']
max_height

property type: Float

min_height

property type: Float

values = <bokeh.charts._properties.Dimension object>
class BoxPlotBuilder(*args, **kws)

Produces Box Glyphs for groups of data.

Handles box plot options to produce one to many boxes, which are used to describe the distribution of a variable.

glyph

alias of BoxGlyph

default_attributes = {'outlier_fill_color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1ace91d0>, 'group': <bokeh.charts._attributes.GroupAttr object at 0x2adf1ace92d0>, 'color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1ace9190>, 'label': <bokeh.charts._attributes.GroupAttr object at 0x2adf1ace9150>, 'whisker_color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1ace9250>, 'stack': <bokeh.charts._attributes.GroupAttr object at 0x2adf1ace9290>}
marker

property type: String

The marker type to use (e.g., circle) if outliers=True.

outliers

property type: Bool

Whether to display markers for any outliers.

class HistogramBuilder(*args, **kws)

Generates one to many histograms with unique attributes.

The HistogramBuilder is responsible for producing a chart containing one to many histograms from table-like inputs.

glyph

alias of HistogramGlyph

get_extra_args()
bins

property type: Int

Number of bins to use for the histogram. (default: None (use Freedman-Diaconis rule)

density

property type: Bool

Whether to normalize the histogram. (default: True)

If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. If False, the result will contain the number of samples in each bin.

For more info check numpy.histogram function documentation.

class LineBuilder(*args, **kws)

This is the Line class and it is in charge of plotting Line charts in an easy and intuitive way. Essentially, we provide a way to ingest the data, make the proper calculations and push the references into a source object. We additionally make calculations for the ranges. And finally add the needed lines taking the references from the source.

attr_measurement(attr_name)

Detect if the attribute has been given measurement columns.

default_attributes = {'color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1acb7ed0>, 'dash': <bokeh.charts._attributes.DashAttr object at 0x2adf1acc1190>}
dimensions = ['y', 'x']
measure_input
measures
class ScatterBuilder(*args, **kws)

This is the Scatter class and it is in charge of plotting Scatter charts in an easy and intuitive way.

Essentially, we provide a way to ingest the data, make the proper calculations and push the references into a source object. We additionally make calculations for the ranges. And finally add the needed glyphs (markers) taking the references from the source.

default_attributes = {'color': <bokeh.charts._attributes.ColorAttr object at 0x2adf1acad2d0>, 'marker': <bokeh.charts._attributes.MarkerAttr object at 0x2adf1ace9050>}