- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- Labs The future of collective knowledge sharing
- About the company

New search experience powered by AI
Stack Overflow is leveraging AI to summarize the most relevant questions and answers from the community, with the option to ask follow-up questions in a conversational format.
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Get early access and see previews of new features.
How can I add text annotation in Bokeh?
I'm looking for Matplotlib type 1 text annotation in Bokeh, but I couldn't find it in the their user guide 2 or in the references.
- The answers which have been given more recently are correct and should now be 'accepted' -- if you could be a good citizen and de-select my answer, I can delete mine in favour of the more recent. Thanks! – user908094 Jul 11, 2016 at 9:54
2 Answers 2
As of version 0.12.2, to add text annotations you would use the "label" glyph.
Please find a full example in the documentation: http://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#userguide-annotations

This 'text' functionality falls under 'glyphs': you'll find the page here

- 3 the link is broken. With version 0.12 I would suggest to use the 'lable' glyph (see also new answer below): bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#labels – queise Jul 9, 2016 at 19:39
- for Bokeh 2.3.2 Label is under bokeh.models.annotations : docs.bokeh.org/en/latest/docs/reference/models/… – Marc Compere Jul 19, 2021 at 14:08
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .
Not the answer you're looking for? Browse other questions tagged bokeh or ask your own question .
- The Overflow Blog
- Multiplayer programming on mobile: a chat with Replit CEO Amjad Masad
- Featured on Meta
- Sunsetting Winter/Summer Bash: Rationale and Next Steps
- Expanding Discussions: Let's talk about flag reasons
- Temporary policy: Generative AI (e.g., ChatGPT) is banned
- OverflowAI Search is now available for alpha testing (September 13, 2023)
- Collectives Updates to the Community Bulletin in the Right Sidebar
Hot Network Questions
- Why do some MTG cards specify "land and/or Gate"?
- What are the risks for using an old iPad?
- stupid + stupid = brilliant in scientific computing
- How can I fit a parabola to 2D data points?
- Find the smallest integer multiple of a Decimal
- What is the name of this green 2-pole DC power connector?
- Why can't hard links reference files on other filesystems?
- Software for quantum electrodynamics?
- How is a student’s research experience evaluated for a PhD application?
- Absolute Beginner: Can anyone tell me if this PCB is using AC or DC and if DC what component is converting the AC to DC on it?
- How do I politely get my coworker to stop communicating with me in morse code?
- Book like 'Ancestry and Culture' but with a lot more races included
- Debian 12 (bookworm): Installing a software RAID 1 fails with grub error
- Why are n public keys needed for reconstitution of an x of n multisig?
- Intuition behind the Euclidean orthogonal projection
- Who or what was the inspiration for Jessica Rabbit?
- A Simple Tetris game made with C++ and ncurses
- Function to replace values of elements of matrix with 0 unless the value is -1
- Detecting if a video mode is supported by INT 0x10
- How do we know what physics or science textbook said is correct?
- Is there a maximum practical telescope aperture for viewing (through a filter) a solar eclipse?
- Access to Google Drive
- Is it safe to become separated from your passport in a foreign country?
- What does verb + 損 mean?
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
Adding Annotations ¶
Bokeh includes several different types of annotations to allow users to add supplemental information to their visualizations.
Title annotations allow descriptive text to be rendered around the edges of a plot.
When using bokeh.plotting or bokeh.Charts , the quickest way to add a basic title is to pass the text as the title parameter to Figure or any Chart function:
The default title is normally on the top of a plot, aligned to the left. But which side of the plot the default title appears on can be controlled by the title_location parameter:
The default Title is accessible through the Plot.title property. Visual properties for font, border, background, and others can be set directly on .title . Here is an example that sets font and background properties as well as the title text and title alignment using .title :
Note that the alignment is measured along the direction of text. For example for titles on the left side of a plot “left” will be in the lower corner.
In addition to the default title, it is possible to create and add additional Title objects to plots using the add_layout method of Plots:
If a title and a sticky toolbar are set to the same side, they will occupy the same space:
If the plot size is large enough, this can result in a more compact plot. However if the plot size is not large enough, the title and toolbar may visually overlap in way that is not desirable.
It is possible to create Legend annotations easily by specifying legend arguments to the glyph methods, when creating a plot.

Basic Legend Label ¶
To provide a simple explicit label for a glypy, pass the legend_label keyword argument:
If multiple glyphs are given the same label, they will all be combined in to a single legend item with that label.
Automatic Grouping (Python) ¶
It is often desirable to generate multiple legend items by grouping the values in a data source column. It is possible for Bokeh to perform such a grouping by passing the legend_group keyword argument to a glyph method:
When this method is used, the grouping is performed immediately in Python, and subsequent Python code will be able to see the individual legend items in Legend.items property. If desired, these items can be re-arranged or modified.
To use this feature, a source argument must also be provided to the glyph method. Additionally, the column to be grouped must already be present in the data source at that point.
Automatic Grouping (Browser) ¶
It is also possible to specify that the grouping should happen on the JavaScript side, in the browser. This may be desirable, e.g. if the grouping should happen on a column that is only computed on the JavaScript side.
In this case the Python code does not see multiple items in Legend.items . Instead there is only a single item that represents the grouping to perform in the browser.
Manual Legends ¶
It is also possible to not specify any of the legend arguments, and manually build a Legend by hand. An example of this can be found in examples/models/file/legends.py :
Explicit Index ¶
Other times, it may be useful to explicitly tell Bokeh which index into a ColumnDataSource should be used when drawing a legend item. In particular, if you want to draw multiple legend items for “multi” glyphs such as MultiLine or Patches . This is accomplished by specifying an index for the legend item as shown below.
Interactive Legends ¶
It’s also possible to configure legends to be interactive, so that clicking or tapping on legend entries affects the corresponding glyph visibility. See the Interactive Legends section of the User’s Guide for more information and examples.
Interactive Legends features currently work on the first, “per-glyph” style legends. Legends that are created by specifying a column to automatically group do no yet support interactive features.
Color Bars ¶
A ColorBar can be created using a ColorMapper instance, which contains a color palette. Both on- and off-plot color bars are supported; the desired location can be specified when adding the ColorBar to the plot.
This example depends on the open-source NumPy library in order to generate demonstration data.
Arrow annotations can be used to connect glyphs and label annotations or to simply highlight plot regions. Arrows are compound annotations, meaning that their start and end attributes are themselves other ArrowHead annotations. By default, the Arrow annotation is one-sided with the end set as an OpenHead -type arrow head (an open-backed wedge style) and the start property set to None . Double-sided arrows can be created by setting both the start and end properties as appropriate ArrowHead subclass instances.
Arrows have standard line properties to set the color and appearance of the arrow shaft:
Arrows may also be configured to refer to additional non-default x- or y-ranges with the x_range and y_range properties, in the same way as Twin Axes .
Additionally any arrow head objects in start or end have a size property to control how big the arrow head is, as well as both line and fill properties. The line properties control the outline of the arrow head, and the fill properties control the interior of the arrow head (if applicable).
A Band will create a dimensionally-linked “stripe”, either located in data or screen coordinates. One common use for the Band annotation is to indicate uncertainty related to a series of measurements.
Box Annotations ¶
A BoxAnnotation can be linked to either data or screen coordinates in order to emphasize specific plot regions. By default, box annotation dimensions (e.g. left or top ) default will extend the annotation to the edge of the plot area.
Labels are text elements that can be used to annotate either glyphs or plot regions.
To create a single text label, use the Label annotation. This annotation is configured with a text property containing the text to be displayed, as well as x and y properties to set the position (in screen or data space units). Additionally a render mode "canvas" or "css" may be specified. Finally, labels have text , border_line , and background_fill properties. These control the visual appearance of the text, as well as the border and background of the bounding box for the text:
To create several labels at once, possibly to easily annotate another existing glyph, use the LabelSet annotation, which is configured with a data source, with the text and x and y positions are given as column names. LabelSet objects can also have x_offset and y_offset , which specify a distance in screen space units to offset the label positions from x and y . Finally the render level may be controlled with the level property, to place the label above or underneath other renderers:
The following example illustrates the use of both:
Slope annotations are lines which may be sloped and extend to the edge of the plot area.
Span annotations are lines that have a single dimension (width or height) and extend to the edge of the plot area.
A Whisker will create a dimensionally-linked “stem”, either located in data or screen coordinates. Indicating error or uncertainty for measurements at a single point would be one common use for the Whisker annotation.

IMAGES
VIDEO
COMMENTS
User guide Basic plotting Annotations Annotations # Bokeh includes several different types of annotations you can use to add supplemental information to your visualizations. Titles # Use Title annotations to add descriptive text which is rendered around the edges of a plot.
2 Answers Sorted by: 21 As of version 0.12.2, to add text annotations you would use the "label" glyph. from bokeh.models import Label p = figure (...) mytext = Label (x=70, y=70, text='here your text') p.add_layout (mytext) show (p)
Bokeh automatically adds a legend to your plot if you include the legend_label attribute when calling the renderer function. For example: p.circle(x, y3, legend_label="Objects") This adds a legend with the entry “Objects” to your plot. Use the properties of the Legend object to customize the legend. For example:
Bokeh includes several different types of annotations you can use to add supplemental information to your visualizations. Titles ¶ Use Title annotations to add descriptive text which is rendered around the edges of a plot.
Labels¶. Labels are text elements that can be used to annotate either glyphs or plot regions. To create a single text label, use the Label annotation. This annotation is configured with a text property containing the text to be displayed, as well as x and y properties to set the position (in screen or data space units).