Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multi-line plot title in bokeh?

Tags:

python

bokeh

How do you create a multiline plot title in bokeh?... same question as https://github.com/bokeh/bokeh/issues/994
Is this resolved yet?

import bokeh.plotting as plt

plt.output_file("test.html")
plt.text(x=[1,2,3], y = [0,0,0], text=['hello\nworld!', 'hello\nworld!', 'hello\nworld!'], angle = 0)
plt.show()

Additionally, can the title text string accept rich text?

like image 975
asdf Avatar asked Sep 23 '16 17:09

asdf


People also ask

How do you plot multiple lines on bokeh?

With Bokeh's bokeh. plotting interface, you can add more glyphs to your plot: To add more line graphs to your plot, all you need to do is call the line() function multiple times. In this example, you also assign a different color to each of the lines by passing a different named color to each line's color argument.

Does Bokeh use Matplotlib?

Matplotlib, seaborn, ggplot, and Pandas¶Uses bokeh to display a Matplotlib Figure. You can store a bokeh plot in a standalone HTML file, as a document in a Bokeh plot server, or embedded directly into an IPython Notebook output cell. Parameters: fig (matplotlib.


1 Answers

In recent versions of Bokeh, labels and text glyphs can accept newlines in the text, and these will be rendered as expected. For multi-line titles, you will have to add explicit Title annotations for each line you want. Here is a complete example:

from bokeh.io import output_file, show
from bokeh.models import Title
from bokeh.plotting import figure

output_file("test.html")

p = figure(x_range=(0, 5))
p.text(x=[1,2,3], y = [0,0,0], text=['hello\nworld!', 'hello\nworld!', 'hello\nworld!'], angle = 0)

p.add_layout(Title(text="Sub-Title", text_font_style="italic"), 'above')
p.add_layout(Title(text="Title", text_font_size="16pt"), 'above')

show(p)

Which produces:

enter image description here

Note that you are limited to the standard "text properties" that Bokeh exposes, since the underlying HTML Canvas does not accept rich text. If you need something like that it might be possible with a custom extension

like image 51
bigreddot Avatar answered Sep 22 '22 05:09

bigreddot