- Bokeh - Discussion
- Bokeh - Useful Resources
- Bokeh - Quick Guide
- Bokeh - Developing with JavaScript
- Bokeh - WebGL
- Bokeh - Extending Bokeh
- Bokeh - Embedding Plots and Apps
- Bokeh - Exporting Plots
- Bokeh - Using Bokeh Subcommands
- Bokeh - Server
- Bokeh - Adding Widgets
- Bokeh - Customising legends
- Bokeh - Styling Visual Attributes
- Bokeh - Plot Tools
- Bokeh - Layouts
- Bokeh - Filtering Data
- Bokeh - ColumnDataSource
- Bokeh - Pandas
- Bokeh - Annotations and Legends
- Bokeh - Axes
- Bokeh - Setting Ranges
- Bokeh - Specialized Curves
- Bokeh - Wedges and Arcs
- Bokeh - Rectangle, Oval and Polygon
- Bokeh - Circle Glyphs
- Bokeh - Area Plots
- Bokeh - Plots with Glyphs
- Bokeh - Basic Concepts
- Bokeh - Jupyter Notebook
- Bokeh - Getting Started
- Bokeh - Environment Setup
- Bokeh - Introduction
- Bokeh - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bokeh - Annotations and Legends
Annotations are pieces of explanatory text added to the diagram. Bokeh plot can be annotated by way of specifying plot title, labels for x and y axes as well as inserting text labels anywhere in the plot area.
Plot title as well as x and y axis labels can be provided in the Figure constructor itself.
fig = figure(title, x_axis_label, y_axis_label)
In the following plot, these properties are set as shown below −
from bokeh.plotting import figure, output_file, show import numpy as np import math x = np.arange(0, math.pi*2, 0.05) y = np.sin(x) fig = figure(title = "sine wave example", x_axis_label = angle , y_axis_label = sin ) fig.pne(x, y,pne_width = 2) show(p)
Output
The title’s text and axis labels can also be specified by assigning appropriate string values to corresponding properties of figure object.
fig.title.text = "sine wave example" fig.xaxis.axis_label = angle fig.yaxis.axis_label = sin
It is also possible to specify location, apgnment, font and color of title.
fig.title.apgn = "right" fig.title.text_color = "orange" fig.title.text_font_size = "25px" fig.title.background_fill_color = "blue"
Adding legends to the plot figure is very easy. We have to use legend property of any glyph method.
Below we have three glyph curves in the plot with three different legends −
from bokeh.plotting import figure, output_file, show import numpy as np import math x = np.arange(0, math.pi*2, 0.05) fig = figure() fig.pne(x, np.sin(x),pne_width = 2, pne_color = navy , legend = sine ) fig.circle(x,np.cos(x), pne_width = 2, pne_color = orange , legend = cosine ) fig.square(x,-np.sin(x),pne_width = 2, pne_color = grey , legend = -sine ) show(fig)