Bokeh’s themes are a set of pre-defined design parameters that you can apply to
your plots. Themes can include settings for parameters such as colors, fonts,
or line styles.
Bokeh comes with five built-in themes to quickly change
the appearance of one or more plots: caliber, dark_minimal,
light_minimal, night_sky, and contrast.
To use one of the built-in themes, assign the name of the theme you want to use
to the theme property of your document.
Palettes are sequences of RGB(A) hex strings that define a colormap. The
sequences you use for defining colormaps can be either lists or tuples. Once you
have created a colormap, you can use it with the color attribute of many
plot objects from bokeh.plotting.
Bokeh includes several pre-defined palettes, such as the standard Brewer
palettes. To use one of those pre-defined palettes, import it from the
bokeh.palettes module. When you import “Spectral6”, for example, Bokeh gives
you access to a six element list of RGB(A) hex strings from the Brewer
“Spectral” colormap:
Use Bokeh’s color mappers to encode a sequence of data into a palette of colors
that are based on the values in that sequence. You can then set a marker
object’s color attribute to your color mapper. Bokeh includes several types
of mappers to encode colors:
linear_cmap(): Maps a range of numeric values across the
available colors from high to low. For example, a range of [0,99] given the
colors [‘red’, ‘green’, ‘blue’] would be mapped as follows:
x<0:'red'# values < low are clamped0>=x<33:'red'33>=x<66:'green'66>=x<99:'blue'99>=x:'blue'# values > high are clamped
log_cmap(): Similar to linear_cmap but uses a natural
log scale to map the colors.
These mapper functions return a DataSpec property. Pass this property to
the color attribute of the glyph you want to use it with.
The dataspec that the mapper function returns includes a bokeh.transform.
You can access this data to use the result of the mapper function in a different
context. To create a ColorBar, for example:
frombokeh.modelsimportColorBar,ColumnDataSourcefrombokeh.palettesimportSpectral6frombokeh.plottingimportfigure,output_file,showfrombokeh.transformimportlinear_cmapoutput_file("styling_linear_mappers.html",title="styling_linear_mappers.py example")x=[1,2,3,4,5,7,8,9,10]y=[1,2,3,4,5,7,8,9,10]#Use the field name of the column sourcemapper=linear_cmap(field_name='y',palette=Spectral6,low=min(y),high=max(y))source=ColumnDataSource(dict(x=x,y=y))p=figure(width=300,height=300,title="Linear Color Map Based on Y")p.circle(x='x',y='y',line_color=mapper,color=mapper,fill_alpha=1,size=12,source=source)color_bar=ColorBar(color_mapper=mapper['transform'],width=8)p.add_layout(color_bar,'right')show(p)
To style the visual attributes of Bokeh plots, you need to know what the
available properties are. The full reference guide contains all properties of
every object individually. However, there are three groups of properties that
many objects have in common. They are:
line properties: line color, width, etc.
fill properties: fill color, alpha, etc.
text properties: font styles, colors, etc.
This section contains more details about some of the most common properties.
a dict mapping string names to custom pattern implementations. The name
can be referred to by hatch_pattern. For example, if the following value
is set for hatch_extra:
hatch_extra={'mycustom':ImageURLTexture(url=...)}
then the name "mycustom" may be set as a hatch_pattern.
Glyph renderers, axes, grids, and annotations all have a visible property.
Use this property to turn them on and off.
frombokeh.ioimportoutput_file,showfrombokeh.plottingimportfigure# We set-up a standard figure with two linesp=figure(width=500,height=200,tools='')visible_line=p.line([1,2,3],[1,2,1],line_color="blue")invisible_line=p.line([1,2,3],[2,1,2],line_color="pink")# We hide the xaxis, the xgrid lines, and the pink lineinvisible_line.visible=Falsep.xaxis.visible=Falsep.xgrid.visible=Falseoutput_file("styling_visible_property.html")show(p)
This can be particularly useful in interactive examples with a Bokeh server or
CustomJS.
frombokeh.ioimportoutput_file,showfrombokeh.layoutsimportlayoutfrombokeh.modelsimportBoxAnnotation,Togglefrombokeh.plottingimportfigureoutput_file("styling_visible_annotation_with_interaction.html")p=figure(width=600,height=200,tools='')p.line([1,2,3],[1,2,1],line_color="#0072B2")pink_line=p.line([1,2,3],[2,1,2],line_color="#CC79A7")green_box=BoxAnnotation(left=1.5,right=2.5,fill_color='#009E73',fill_alpha=0.1)p.add_layout(green_box)# Use js_link to connect button active property to glyph visible propertytoggle1=Toggle(label="Green Box",button_type="success",active=True)toggle1.js_link('active',green_box,'visible')toggle2=Toggle(label="Pink Line",button_type="success",active=True)toggle2.js_link('active',pink_line,'visible')show(layout([p],[toggle1,toggle2]))
Bokeh objects have several properties related to colors. Use those color
properties to control the appearance of lines, fills, or text, for example.
Use one of these options to define colors in Bokeh:
Any of the named CSS colors, such as 'green' or 'indigo'. You can
also use the additional name 'transparent' (equal to '#00000000').
An RGB(A) hex value, such as '#FF0000' (without alpha information) or
'#44444444' (with alpha information).
A CSS4 rgb(), rgba(), or hsl()color string, such as
'rgb(01270/1.0)', 'rgba(255,0,127,0.6)', or
'hsl(60deg100%50%/1.0)'.
A 3-tuple of integers (r,g,b) (where r, g, and b are integers
between 0 and 255).
A 4-tuple of (r,g,b,a) (where r, g, and b are integers between 0
and 255 and a is a floating-point value between 0 and 1).
A 32-bit unsigned integer representing RGBA values in a 0xRRGGBBAA
byte order pattern, such as 0xffff00ff or 0xff0000ff.
To define a series of colors, use an array of color data such as a list or the
column of a ColumnDataSource. This also includes
NumPy arrays.
For example:
importnumpyasnpfrombokeh.plottingimportfigure,output_file,showoutput_file("specifying_colors.html")x=[1,2,3]y1=[1,4,2]y2=[2,1,4]y3=[4,3,2]# use a single RGBA colorsingle_color=(255,0,0,0.5)# use a list of different colorslist_of_colors=["hsl(60deg 100% 50% / 1.0)","rgba(0, 0, 255, 0.9)","LightSeaGreen",]# use a series of color values as numpy arraynumpy_array_of_colors=np.array([0xFFFF00FF,0x00FF00FF,0xFF000088,],np.uint32,)p=figure(title="Specifying colors")# add glyphs to plotp.line(x,y1,line_color=single_color)p.circle(x,y2,radius=0.12,color=list_of_colors)p.triangle(x,y3,size=30,fill_color=numpy_array_of_colors)show(p)
In addition to specifying the alpha value of a color when defining the color
itself, you can also set an alpha value separately by using the
line_alpha or fill_alpha properties of a glyph.
In case you define a color with an alpha value and also explicitly provide an
alpha value through a line_alpha or fill_alpha property at the same
time, the following happens: If your color definition does include an alpha
value (such as '#00FF0044' or 'rgba(255,0,127,0.6)'), this alpha
value takes precedence over the alpha value you provide through the objects’s
property. Otherwise, the alpha value defined in the objects’s property is used.
The following figure demonstrates each possible combination of using RGB and
RGBA colors together with the line_alpha or fill_alpha properties:
Note
If you use
Bokeh’s plotting interface, you also
have the option to specify color and/or alpha as keywords when
calling a renderer method. Bokeh automatically applies these values to the
corresponding fill and line properties of your glyphs.
You then still have the option to provide additional fill_color,
fill_alpha, line_color, and line_alpha arguments as well. In
this case, the former will take precedence.
When setting visual properties of Bokeh objects, you use either screen units or
data-space units:
Screen units use raw numbers of pixels to specify height or width
Data-space units are relative to the data and the axes of the plot
Take a 400 pixel by 400 pixel graph with x and y axes ranging from 0
through 10, for example. A glyph that is one fifth as wide and tall as the graph
would have a size of 80 screen units or 2 data-space units.
Objects in Bokeh that support both screen units and data-space units usually
have a dedicated property to choose which unit to use. This unit-setting
property is the name of the property with an added _units. For
example: A Whiskerannotation has the property upper. To
define which unit to use, set the upper_units property to either
'screen' or 'data'.
If you want to customize the appearance of any element of your Bokeh plot, you
first need to identify which object you want to modify. As described in
Defining key concepts, Bokeh plots are a combination of Python objects that
represent all the different parts of your plot: its grids, axes, and glyphs, for
example.
To query for any Bokeh plot object, use the select() method on Plot. For
example, to find all PanTool objects in a plot:
>>> p.select(type=PanTool)[<bokeh.models.tools.PanTool at 0x106608b90>]
You can also use the select() method to query on other attributes as well:
>>> p.circle(0,0,name="mycircle")<bokeh.plotting.Figure at 0x106608810>>>> p.select(name="mycircle")[<bokeh.models.renderers.GlyphRenderer at 0x106a4c810>]
This query method can be especially useful when you want to style visual
attributes of Styling glyphs.
In addition to the individual plot elements, a Plot object itself also has
several visual characteristics that you can customize: the dimensions of the
plot, its backgrounds, borders, or outlines, for example. This section describes
how to change these attributes of a Bokeh plot.
The example code primarily uses the bokeh.plotting interface to create plots.
However, the instructions apply regardless of how a Bokeh plot was created.
To change the width and height of a Plot, use its width and
height attributes. Those two attributes use screen units. They
control the size of the entire canvas area, including any axes or titles (but
not the toolbar).
If you are using the bokeh.plotting interface, you can pass these values to
figure() directly:
frombokeh.plottingimportfigure,output_file,showoutput_file("dimensions.html")# create a new plot with specific dimensionsp=figure(width=700)p.height=300p.circle([1,2,3,4,5],[2,5,8,2,7],size=10)show(p)
To automatically adjust the width or height of your plot in relation to the
available space in the browser, use the plot’s
sizing_mode property.
To control how the plot scales to fill its container, see the documentation for
layouts, in particular the sizing_mode property of
LayoutDOM.
If you set sizing_mode to anything different than fixed, Bokeh adjusts
the width and height as soon as a plot is rendered. However,
Bokeh uses width and height to calculate the initial aspect
ratio of your plot.
Plots will only resize down to a minimum of 100px (height or width) to prevent
problems in displaying your plot.
To style the title of your plot, use the Title annotation, which is available
as the .title property of the Plot.
You can use most of the standard text properties. However, text_align and
text_baseline do not apply. To position the title relative to the entire
plot, use the properties align and
offset instead.
As an example, to set the color and font style of the title text, use
plot.title.text_color:
To adjust the border fill style, use the border_fill_color and
border_fill_alpha properties of the Plot object. You can also set the
minimum border on each side (in screen units) with these properties:
min_border_left
min_border_right
min_border_top
min_border_bottom
Additionally, if you set min_border, Bokeh applies a minimum border setting
to all sides as a convenience. The min_border default value is 40px.
To style the fill, line, or text properties of a glyph, you first need to
identify which GlyphRenderer you want to customize. If you are using the
bokeh.plotting interface, the glyph functions return the renderer:
>>> r=p.circle([1,2,3,4,5],[2,5,8,2,7])>>> r<bokeh.models.renderers.GlyphRenderer at 0x106a4c810>
Next, obtain the glyph itself from the .glyph attribute of a
GlyphRenderer:
>>> r.glyph<bokeh.models.glyphs.Circle at 0x10799ba10>
This is the object to set fill, line, or text property values for:
To customize the styling of selected and non-selected glyphs, set the
selection_glyph and nonselection_glyph attributes of the GlyphRenderer.
You can either set them manually or by passing them to add_glyph().
The plot below uses the bokeh.plotting interface to set these attributes.
Click or tap any of the circles on the plot to see the effect on the selected
and non-selected glyphs. To clear the selection and restore the original state,
click anywhere in the plot outside of a circle.
frombokeh.ioimportoutput_file,showfrombokeh.modelsimportCirclefrombokeh.plottingimportfigureoutput_file("styling_selections.html")plot=figure(width=400,height=400,tools="tap",title="Select a circle")renderer=plot.circle([1,2,3,4,5],[2,5,8,2,7],size=50)selected_circle=Circle(fill_alpha=1,fill_color="firebrick",line_color=None)nonselected_circle=Circle(fill_alpha=0.2,fill_color="blue",line_color="firebrick")renderer.selection_glyph=selected_circlerenderer.nonselection_glyph=nonselected_circleshow(plot)
If you just need to set the color or alpha parameters of the selected or
non-selected glyphs, provide color and alpha arguments to the glyph function,
prefixed by "selection_" or "nonselection_":
frombokeh.ioimportoutput_file,showfrombokeh.plottingimportfigureoutput_file("styling_selections.html")plot=figure(width=400,height=400,tools="tap",title="Select a circle")renderer=plot.circle([1,2,3,4,5],[2,5,8,2,7],size=50,# set visual properties for selected glyphsselection_color="firebrick",# set visual properties for non-selected glyphsnonselection_fill_alpha=0.2,nonselection_fill_color="blue",nonselection_line_color="firebrick",nonselection_line_alpha=1.0)show(plot)
If you use the bokeh.models interface, use the
add_glyph() function:
When rendering, Bokeh considers only the visual properties of
selection_glyph and nonselection_glyph. Changing
positions, sizes, etc., will have no effect.
Some Bokeh tools also have configurable visual attributes.
For instance, the various region selection tools and the box zoom tool all have
an overlay. To style their line and fill properties, pass values to the
respective attributes:
importnumpyasnpfrombokeh.modelsimportBoxSelectTool,BoxZoomTool,LassoSelectToolfrombokeh.plottingimportfigure,output_file,showoutput_file("styling_tool_overlays.html")x=np.random.random(size=200)y=np.random.random(size=200)# Basic plot setupplot=figure(width=400,height=400,title='Select and Zoom',tools="box_select,box_zoom,lasso_select,reset")plot.circle(x,y,size=5)select_overlay=plot.select_one(BoxSelectTool).overlayselect_overlay.fill_color="firebrick"select_overlay.line_color=Nonezoom_overlay=plot.select_one(BoxZoomTool).overlayzoom_overlay.line_color="olive"zoom_overlay.line_width=8zoom_overlay.line_dash="solid"zoom_overlay.fill_color=Noneplot.select_one(LassoSelectTool).overlay.line_dash=[10,10]show(plot)
For more information, see the reference guide’s entries for
BoxSelectTool.overlay,
BoxZoomTool.overlay,
LassoSelectTool.overlay,
PolySelectTool.overlay, and
RangeTool.overlay.
To make your toolbar hide automatically, set the toolbar’s
autohide property to True. When you set
autohide to True, the toolbar is visible only when the mouse is inside the
plot area and is otherwise hidden.
frombokeh.plottingimportfigure,output_file,showoutput_file("styling_toolbar_autohide.html")# Basic plot setupplot=figure(width=400,height=400,title='Toolbar Autohide')plot.line([1,2,3,4,5],[2,5,8,2,7])# Set autohide to true to only show the toolbar when mouse is over plotplot.toolbar.autohide=Trueshow(plot)
This section focuses on changing various visual properties of Bokeh plot axes.
To set style attributes on Axis objects, use the xaxis, yaxis, and
axis methods on Plot to first obtain a plot’s Axis objects. For example:
>>> p.xaxis[<bokeh.models.axes.LinearAxis at 0x106fa2390>]
Because there may be more than one axis, this method returns a list of Axis
objects. However, as a convenience, these lists are splattable. This means that
you can set attributes directly on this result, and the attributes will be
applied to all the axes in the list. For example:
p.xaxis.axis_label="Temperature"
This changes the value of axis_label for every x-axis of p, however
many there may be.
The example below demonstrates the use of the xaxis, yaxis, and
axis methods in more details:
frombokeh.plottingimportfigure,output_file,showoutput_file("axes.html")p=figure(width=400,height=400)p.circle([1,2,3,4,5],[2,5,8,2,7],size=10)# change just some things about the x-axisp.xaxis.axis_label="Temp"p.xaxis.axis_line_width=3p.xaxis.axis_line_color="red"# change just some things about the y-axisp.yaxis.axis_label="Pressure"p.yaxis.major_label_text_color="orange"p.yaxis.major_label_orientation="vertical"# change things on all axesp.axis.minor_tick_in=-3p.axis.minor_tick_out=6show(p)
To add or change the text of an axis’ overall label, use the axis_label
property. To add line breaks to the text in an axis label, include \n in
your string.
To control the visual appearance of the label text, use any of the standard
text properties prefixed with axis_label_. For instance, to set the text
color of the label, set axis_label_text_color.
To change the distance between the axis label and the major tick labels, set the
axis_label_standoff property.
Bokeh uses several “ticker” models to decide where to display ticks on axes
(categorical, datetime, mercator, linear, or log scale). To configure the
placements of ticks, use the .ticker property of an axis.
If you use the bokeh.plotting interface, Bokeh chooses an appropriate ticker
placement model automatically.
In case you need to control which ticker placement model to use, you can also
explicitly define a list of tick locations. Assign
FixedTicker with a list of tick locations to an
axis:
frombokeh.plottingimportfigurefrombokeh.models.tickersimportFixedTickerp=figure()# no additional tick locations will be displayed on the x-axisp.xaxis.ticker=FixedTicker(ticks=[10,20,37.4])
As a shortcut, you can also supply the list of ticks directly to an axis’
ticker property:
To control the visual appearance of the major and minor ticks, set the
appropriate line properties, prefixed with major_tick_ and
minor_tick_, respectively.
For instance, to set the color of the major ticks, use
major_tick_line_color. To hide either set of ticks, set the color to
None.
Additionally, to control how far in and out of the plotting area the ticks
extend, use the properties major_tick_in/major_tick_out and
minor_tick_in/minor_tick_out. These values are in screen units.
Therefore, you can use negative values.
To style the text of axis labels, use the TickFormatter object of the axis’
formatter property. Bokeh uses a number of ticker formatters by default in
different situations:
These default tick formatters do not expose many configurable properties.
To control tick formatting at a finer-grained level, use one of the
NumeralTickFormatter or PrintfTickFormatter described below.
Note
To replace a tick formatter on an axis, you must set the formatter
property on an actual Axis object, not on a splattable list. This is
why the following examples use p.yaxis[0].formatter, etc. (with the
subscript [0]).
To control the orientation of major tick labels, use the
major_label_orientation property. This property accepts the
values "horizontal" or "vertical" or a floating-point number
that gives the angle (in radians) to rotate from the horizontal:
There are more properties that you can use to configure Bokeh axes. For a
complete list of all the various attributes that you can set on different
types of Bokeh axes, see the axes section of the
reference guide.
In this section, you will learn how to set the visual properties of grid
lines and grid bands on Bokeh plots.
To obtain a plot’s Grid objects, use the xgrid, ygrid, and grid methods on
Plot. This works similar to the convenience methods for axes:
>>> p.grid[<bokeh.models.grids.Grid at 0x106fa2278>, <bokeh.models.grids.Grid at 0x106fa22e8>]
These methods also return splattable lists. You can set an attribute
on the list as if it was a single object, and the attribute is changed
for every element of the list:
p.grid.line_dash=[42]
Note
The xgrid property provides the grid objects that intersect the
x-axis (meaning vertically oriented objects). Correspondingly, ygrid
provides the grid objects that intersect the y-axis (meaning horizontally
oriented objects).
To configure the visual appearance of grid lines, use a collection of
line properties, prefixed with grid_.
For instance, to set the color of grid lines, use grid_line_color. To hide
grid lines, set their line color to None:
frombokeh.plottingimportfigure,output_file,showoutput_file("gridlines.html")p=figure(width=400,height=400)p.circle([1,2,3,4,5],[2,5,8,2,7],size=10)# change just some things about the x-gridp.xgrid.grid_line_color=None# change just some things about the y-gridp.ygrid.grid_line_alpha=0.5p.ygrid.grid_line_dash=[6,4]show(p)
To configure the visual appearance of minor grid lines, use a collection of
line properties, prefixed with minor_grid_.
For instance, to set the color of grid lines, use minor_grid_line_color. By
default, minor grid lines are hidden (which means that their line color is set
to None):
frombokeh.plottingimportfigure,output_file,showoutput_file("minorgridlines.html")p=figure(width=400,height=400)p.circle([1,2,3,4,5],[2,5,8,2,7],size=10)# change just some things about the y-gridp.ygrid.minor_grid_line_color='navy'p.ygrid.minor_grid_line_alpha=0.1show(p)
Use “bands” to display filled, shaded bands between adjacent grid lines. To
control the visual appearance of these bands, use a collection of
fill properties and hatch properties that are prefixed with band_.
For instance, to set the color of grid bands, use band_fill_color. To hide
grid bands, set their fill color to None (this is the default).
This example defines bands filled with a solid color:
frombokeh.plottingimportfigure,output_file,showoutput_file("grid_band_fill.html")p=figure(width=400,height=400)p.circle([1,2,3,4,5],[2,5,8,2,7],size=10)# change just some things about the x-gridp.xgrid.grid_line_color=None# change just some things about the y-gridp.ygrid.band_fill_alpha=0.1p.ygrid.band_fill_color="navy"show(p)
This example uses bands filled with a hatch pattern:
There are other properties that Bokeh grids support configuring. For a
complete listing of all the various attributes that can be set on Bokeh
plot grids, consult the grids section of the
reference guide.
Similar to the convenience methods for axes and grids, there is a
legend() method on Plot that you can use to
obtain a plot’s Legend objects:
bokeh.models.plots.Plot.legend
>>> p.legend[<bokeh.models.annotations.Legend at 0x106fa2278>]
This method also returns a splattable list. Therefore, you can set an attribute
on the list as if it was a single object, and the attribute is changed
for every element of the list:
In this use-case, you need to specify the legend’s location in absolute terms.
Future releases will add additional options to customize legend positions.
To add or change a legend’s title, use its title property:
plot.legend.title="Division"
To control the visual appearance of the legend title, use any of the standard
text properties prefixed with title_. For instance, to set the font
style of the legend, use title_text_font_style.
To set the distance between the title and the rest of the legend (in pixels),
use the title_standoff property.
To control the visual appearance of the legend labels, use any of the standard
text properties prefixed with label_. For instance, to set the font
style of the labels, use label_text_font_style.
To control the visual appearance of the legend border, use a collection of
line properties, prefixed with border_. For instance, to set the color
of the border, use border_line_color. To make the border invisible, set
the border line color to None.
To control the visual appearance of the legend background, use a collection
of fill properties, prefixed with background_. For instance, to set the
color of the background, use background_fill_color. To make the background
transparent, set the background_fill_alpha to 0.
importnumpyasnpfrombokeh.plottingimportfigure,output_file,showx=np.linspace(0,4*np.pi,100)y=np.sin(x)output_file("legend_background.html")p=figure()p.circle(x,y,legend_label="sin(x)")p.line(x,y,legend_label="sin(x)")p.line(x,2*y,legend_label="2*sin(x)",line_dash=[4,4],line_color="orange",line_width=2)p.square(x,3*y,legend_label="3*sin(x)",fill_color=None,line_color="green")p.line(x,3*y,legend_label="3*sin(x)",line_color="green")# 3*sin(x) curve should be under this legend at initial viewing, so# we can see that the legend is transparentp.legend.location="bottom_right"p.legend.background_fill_color="navy"p.legend.background_fill_alpha=0.5show(p)
To specify the order in which things are drawn, use one of the following render
levels:
image
“lowest” render level, drawn before anything else
underlay
default render level for grids
glyph
default render level for all glyphs (which means they are drawn above grids)
annotation
default render level for annotation renderers
overlay
“highest” render level, for tool overlays
Within a given level, renderers are drawn in the order that they were added.
To specify a render level explicitly, use the level parameter on the
renderer.
For example, to make sure an image is rendered under the grid lines, assign
the render level "image" to the level argument when calling your
image renderer:
p.image(...,level="image")
You can see a complete example with output in the section
Color mapped images.
Bokeh supports mathematical notations expressed in the LaTeX and MathML markup
languages with a growing number of elements. Currently, you can use LaTeX
and MathML notations with axis labels and
tick labels using major_label_overrides(). You can
also use LaTeX with div or
paragraphwidgets.
Bokeh uses the MathJax library to handle LaTeX and MathML. See the official
MathJax documentation for more information on MathJax. If you use the
components() function, make sure to include the bokeh-mathjax- resource in
your html template.
To use LaTeX notation, you can pass a string directly to any supported element.
This string needs to begin and end with one of the
MathJax default delimiters. These delimiters are $$...$$, \[...\],
and \(...\). For example: r"$$\sin(x)$$".
LaTeX and axis labels
To use LaTeX notation as an axis label, pass a raw string literal beginning
and ending with MathJax default delimiters and containing LaTeX notation
to the axis_label property of an axis. For
example:
To add LaTeX notations to your tick labels, use the
major_label_overrides() function with an axis.
This function is used to replace values for existing tick labels with custom
text. It accepts a dictionary with the tick label’s original value as the
key and your custom value as the dict’s value.
Use this function to replace any plain text tick labels with LaTeX notation:
fromnumpyimportarangefrombokeh.plottingimportfigure,showx=arange(1,4.5,0.25)y=1/xplot=figure(height=200)plot.circle(x,y,fill_color="blue",size=5)plot.line(x,y,color="darkgrey")plot.xaxis.axis_label="Resistance"plot.xaxis.ticker=[1,2,3,4]plot.yaxis.axis_label="Current at 1 V"plot.xaxis.major_label_overrides={1:r"$$1\Omega$$",2:r"$$2\Omega$$",3:r"$$3\Omega$$",4:r"$$4\Omega$$",}show(plot)
To add mathematical notations written in MathML, use Bokeh’s
MathML model directly. This model has a text
property that accepts a string containing MathML. For example: