Bokeh¶
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
Courbe¶
from bokeh.io import curdoc
from bokeh.plotting import figure
# apply theme to current document
curdoc().theme = "dark_minimal"
# create a plot
p = figure(title='Theme: dark minimal', plot_height=250)
# add a renderer
p.line(x, y)
# show the results
show(p)
p.circle(x, y, color='red', size=20)
show(p)
# chage plot size
p.plot_width = 300
p.plot_height = 300
show(p)
# create a plot
p = figure(title='Theme: dark minimal',
y_range=(0, 8),
x_range=(0, 6),
plot_height=250)
p.line(x, y)
p.circle(x, y, color='red', size=20)
show(p)
p.y_range
Range1d(
id = '2400', …)
p.x_range
Range1d(
id = '2398', …)
Axes logarithmique¶
# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
# create a new plot with a logarithmic axis type
p = figure(
title="Logarithmic axis",
plot_height=300,
y_axis_type="log",
)
# add some renderers
p.line(x, x, legend_label="y=x")
p.circle(x, x, legend_label="y=x", fill_color="white", size=8)
p.line(x, y0, legend_label="y=x^2", line_width=3)
p.line(x, y1, legend_label="y=10^x", line_color="red")
show(p)
Grille¶
x = [1, 2, 3, 4, 5]
y = [4, 5, 5, 7, 2]
p = figure(
title="Customized grid lines example",
sizing_mode="stretch_width",
max_width=500,
plot_height=250,
)
# add a renderer
p.line(x, y, line_color="green", line_width=2)
# change just some things about the x-grid
p.xgrid.grid_line_color = "red"
p.xgrid.grid_line_width = 5
# change just some things about the y-grid
p.ygrid.grid_line_alpha = 0.8
p.ygrid.grid_line_dash = [6, 4]
show(p)
# create a plot
p = figure(
title='Bandes de couleurs',
sizing_mode="stretch_width",
max_width=500,
plot_height=250,
background_fill_color='white'
)
# add a renderer
p.line(x, y, line_color="green", line_width=2)
# add bands to the y-grid
p.ygrid.band_fill_color = "olive"
p.ygrid.band_fill_alpha = 0.1
p.xgrid.bounds = (2, 4)
show(p)
p.title="Couleur d'arrièrefond"
p.background_fill_color = (204, 255, 255)
p.border_fill_color = (102, 204, 255)
p.outline_line_color = (0, 0, 255)
# show the results
show(p)
Barre d’outil¶
p.title="Barre d'outils"
p.background_fill_color = 'white'
p.border_fill_color = 'lightblue'
p.toolbar_location='below'
show(p)
p.title="Masqer la barre d'outils"
p.toolbar.autohide = True
p.toolbar.logo = None
show(p)
Tool tips¶
from bokeh.models.tools import HoverTool
p = figure(
toolbar_location=None,
tools=[HoverTool()],
tooltips="Data point @x has the value @y",
sizing_mode="stretch_width",
plot_height=250,
max_width=400
)
p.line(x, y, line_width=2)
p.circle(x, y, size=20, color='red')
show(p)