请注意,Bokeh绘图使用|博克。绘图|界面附带一组默认的工具和默认的视觉样式。看到了吗 设置视觉属性样式 有关如何自定义打印的视觉样式的信息,以及 配置打印工具 有关更改或指定工具的信息。
要在绘图上散布圆形标记,请使用 circle() 方法 Figure :
circle()
Figure
from bokeh.plotting import figure, output_file, show # output to static HTML file output_file("line.html") p = figure(plot_width=400, plot_height=400) # add a circle renderer with a size, color, and alpha p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5) # show the results show(p)
同样,使用正方形 square() 方法 Figure :
square()
from bokeh.plotting import figure, output_file, show # output to static HTML file output_file("square.html") p = figure(plot_width=400, plot_height=400) # add a square renderer with a size, color, and alpha p.square([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="olive", alpha=0.5) # show the results show(p)
Bokeh中有很多标记类型,单击下面列表中的条目可以查看所有标记的详细信息和示例图:
asterisk()
circle_cross()
circle_dot()
circle_x()
circle_y()
cross()
dash()
dot()
diamond()
diamond_cross()
diamond_dot()
hex()
hex_dot()
inverted_triangle()
plus()
square_cross()
square_dot()
square_pin()
square_x()
triangle()
triangle_dot()
triangle_pin()
x()
y()
所有标记都具有相同的属性集: x , y , size 中 screen units ) angle (默认为弧度)。另外, circle() 有一个 radius 属性,可用于指定 data-space units .
x
y
size
angle
radius
下面是一个示例,演示如何从 x 和 y 使用 line() 字形方法:
line()
from bokeh.plotting import figure, output_file, show output_file("line.html") p = figure(plot_width=400, plot_height=400) # add a line renderer p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2) show(p)
对于某些类型的数据,可能更适合在数据点之间绘制离散步骤,而不是用直线段连接点。这个 step() glyph方法可用于完成此操作:
step()
from bokeh.plotting import figure, output_file, show output_file("line.html") p = figure(plot_width=400, plot_height=400) # add a steps renderer p.step([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2, mode="center") show(p)
步进级别可以在x坐标之前、之后或居中绘制,如 mode 参数。
mode
有时一次绘制多条线是很有用的。这可以通过 multi_line() 字形方法:
multi_line()
from bokeh.plotting import figure, output_file, show output_file("patch.html") p = figure(plot_width=400, plot_height=400) p.multi_line([[1, 3, 2], [3, 4, 6, 6]], [[2, 1, 4], [4, 7, 8, 5]], color=["firebrick", "navy"], alpha=[0.8, 0.3], line_width=4) show(p)
注解
此字形与大多数其他字形不同。它不接受一维列表或标量值数组,而是接受每行的x和y位置的“列表列表”,参数xs和ys。multi_line还需要每行一个标量值或一个标量列表,用于颜色、alpha、linewidth等参数。同样,ColumnDataSource可以由“列表列表”和标量列表的长度必须匹配的标量列表组成。
NaN 值可以传递给 line() 和 multi_line() 字形。在这种情况下,最终将得到单个逻辑线对象,这些对象在渲染时具有多个不相交的组件:
NaN
from bokeh.plotting import figure, output_file, show output_file("line.html") p = figure(plot_width=400, plot_height=400) # add a line renderer with a NaN nan = float('nan') p.line([1, 2, 3, nan, 4, 5], [6, 7, 2, 4, 4, 5], line_width=2) show(p)
在某些情况下,希望将在公共索引上对齐的行(例如百分比的时间序列)堆叠起来。这个 vline_stack() 和 hline_stack() 可以使用方便的方法来实现这一点。请注意,这些方法从显式提供的 ColumnDataSource (见章节 提供数据 更多信息。
vline_stack()
hline_stack()
ColumnDataSource
from bokeh.models import ColumnDataSource from bokeh.plotting import figure, output_file, show output_file("vline_stack.html") source = ColumnDataSource(data=dict( x=[1, 2, 3, 4, 5], y1=[1, 2, 4, 3, 4], y2=[1, 4, 2, 2, 3], )) p = figure(plot_width=400, plot_height=400) p.vline_stack(['y1', 'y2'], x='x', source=source) show(p)
当绘制矩形条(通常表示间隔)时,通常使用上面两个系统的混合坐标更方便。Bokeh提供 hbar() 和 vbar() glyphs函数用于此目的。
hbar()
vbar()
若要通过指定(中心)x坐标、宽度以及顶部和底部端点绘制竖线,请使用 vbar() 字形函数:
from bokeh.plotting import figure, output_file, show output_file('vbar.html') p = figure(plot_width=400, plot_height=400) p.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1.2, 2.5, 3.7], color="firebrick") show(p)
要通过指定(中心)y坐标、高度以及左右端点绘制水平条,请使用 hbar() 字形函数:
from bokeh.plotting import figure, output_file, show output_file('hbar.html') p = figure(plot_width=400, plot_height=400) p.hbar(y=[1, 2, 3], height=0.5, left=0, right=[1.2, 2.5, 3.7], color="navy") show(p)
堆垛往往是可取的。这可以通过 vbar_stack() 和 hbar_stack() 方便方法。请注意,这些方法从显式提供的 ColumnDataSource (见章节 提供数据 更多信息)。
vbar_stack()
hbar_stack()
from bokeh.models import ColumnDataSource from bokeh.plotting import figure, output_file, show output_file("hbar_stack.html") source = ColumnDataSource(data=dict( y=[1, 2, 3, 4, 5], x1=[1, 2, 4, 3, 4], x2=[1, 4, 2, 2, 3], )) p = figure(plot_width=400, plot_height=400) p.hbar_stack(['x1', 'x2'], y='y', height=0.8, color=("grey", "lightgrey"), source=source) show(p)
更多堆积钢筋的例子可在本节中找到 处理分类数据 .
画画 轴对齐 矩形(“四边形”)通过指定 left , right , top 和 bottom 位置,使用 quad() 字形函数:
left
right
top
bottom
quad()
from bokeh.plotting import figure, output_file, show output_file('rectangles.html') p = figure(plot_width=400, plot_height=400) p.quad(top=[2, 3, 4], bottom=[1, 2, 3], left=[1, 2, 3], right=[1.2, 2.5, 3.7], color="#B3DE69") show(p)
要通过指定中心点、宽度、高度和角度绘制任意矩形,请使用 rect() 字形函数:
rect()
from math import pi from bokeh.plotting import figure, output_file, show output_file('rectangles_rotated.html') p = figure(plot_width=400, plot_height=400) p.rect(x=[1, 2, 3], y=[1, 2, 3], width=0.2, height=40, color="#CAB2D6", angle=pi/3, height_units="screen") show(p)
Bokeh可以绘制六边形瓷砖,通常用于显示二进制聚集。这个 hex_tile() 方法采用 size parameter to define the size of the hex grid, and axial coordinates 指定存在哪些瓷砖。
hex_tile()
import numpy as np from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.util.hex import axial_to_cartesian output_file("hex_coords.html") q = np.array([0, 0, 0, -1, -1, 1, 1]) r = np.array([0, -1, 1, 0, 1, -1, 0]) p = figure(plot_width=400, plot_height=400, toolbar_location=None) p.grid.visible = False p.hex_tile(q, r, size=1, fill_color=["firebrick"]*3 + ["navy"]*4, line_color="white", alpha=0.5) x, y = axial_to_cartesian(q, r, 1, "pointytop") p.text(x, y, text=["(%d, %d)" % (q,r) for (q, r) in zip(q, r)], text_baseline="middle", text_align="center") show(p)
下面一个更实际的示例使用 hexbin() 函数并绘制颜色映射计数:
hexbin()
import numpy as np from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.transform import linear_cmap from bokeh.util.hex import hexbin n = 50000 x = np.random.standard_normal(n) y = np.random.standard_normal(n) bins = hexbin(x, y, 0.1) p = figure(tools="wheel_zoom,reset", match_aspect=True, background_fill_color='#440154') p.grid.visible = False p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins, fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts))) output_file("hex_tile.html") show(p)
通过调用 hexbin() 方法 Figure .
有向区域是两个序列之间共用一个索引的填充区域。例如,垂直定向区域有一个 x 坐标阵列和两个y坐标阵列, y1 和 y2 ,将在之间填充。
在两个对齐系列之间的一个有向区域可以在垂直方向上用 varea() 或者在水平方向 harea() .
varea()
harea()
from bokeh.plotting import figure, output_file, show output_file("varea.html") p = figure(plot_width=400, plot_height=400) p.varea(x=[1, 2, 3, 4, 5], y1=[2, 6, 4, 3, 5], y2=[1, 4, 2, 2, 3]) show(p)
通常需要堆叠定向区域。这可以通过 varea_stack() 和 harea_stack() 方便方法。请注意,这些方法从显式提供的 ColumnDataSource (见章节 提供数据 更多信息)。
varea_stack()
harea_stack()
from bokeh.models import ColumnDataSource from bokeh.plotting import figure, output_file, show output_file("varea_stack.html") source = ColumnDataSource(data=dict( x=[1, 2, 3, 4, 5], y1=[1, 2, 4, 3, 4], y2=[1, 4, 2, 2, 3], )) p = figure(plot_width=400, plot_height=400) p.varea_stack(['y1', 'y2'], x='x', color=("grey", "lightgrey"), source=source) show(p)
下面是一个示例,演示如何从一维序列生成单个多边形面片glyph x 和 y 使用 patch() 字形方法:
patch()
from bokeh.plotting import figure, output_file, show output_file("patch.html") p = figure(plot_width=400, plot_height=400) # add a patch renderer with an alpha and line width p.patch([1, 2, 3, 4, 5], [6, 7, 8, 7, 3], alpha=0.5, line_width=2) show(p)
有时一次绘制多个多边形面片很有用。这可以通过 patches() 字形方法:
patches()
from bokeh.plotting import figure, output_file, show output_file("patch.html") p = figure(plot_width=400, plot_height=400) p.patches([[1, 3, 2], [3, 4, 6, 6]], [[2, 1, 4], [4, 7, 8, 5]], color=["firebrick", "navy"], alpha=[0.8, 0.3], line_width=2) show(p)
此字形与大多数其他字形不同。它不接受一维列表或标量值数组,而是接受每个补丁的x和y位置的“列表列表”,参数xs和ys。对于颜色、alpha、linewidth等参数,面片还需要每个面片一个标量值或一个标量列表。类似地,ColumnDataSource可以由“列表列表”和标量列表的长度必须匹配的标量列表组成。
就像 line() 和 multi_line() , NaN 值可以传递给 patch() 和 patches() 字形。在这种情况下,最终将得到单个逻辑面片对象,这些对象在渲染时具有多个不相交的组件:
from bokeh.plotting import figure, output_file, show output_file("patch.html") p = figure(plot_width=400, plot_height=400) # add a patch renderer with a NaN value nan = float('nan') p.patch([1, 2, 3, nan, 4, 5, 6], [6, 7, 5, nan, 7, 3, 6], alpha=0.5, line_width=2) show(p)
警告
使用 NaN 当前不支持值。
这个 multi_polygons() glyph使用嵌套来接受与多边形相关的各种信息。任何可以作为 patches() 也可以渲染为 multi_polygons() ,但另外, multi_polygons() 可以渲染每个多边形内的孔。
multi_polygons()
此字形与大多数其他字形不同。它不接受一维列表或标量值数组,而是接受构成每个多边形的外部和孔的x和y位置的3倍嵌套列表。MultiPolygons还需要每个参数(如颜色、alpha、linewidth等)有一个标量值或一个标量列表。类似地,可以使用ColumnDataSource,它由3倍嵌套列表和一个标量列表组成,其中标量列表的长度和顶级列表的长度必须匹配。
下面是一个示例,演示如何从3次嵌套的一维序列生成单个多边形glyph x 和 y 使用 multi_polygons() 字形方法:
from bokeh.plotting import figure, output_file, show output_file('multipolygon_simple.html') p = figure(plot_width=400, plot_height=400) p.multi_polygons(xs=[[[[1, 1, 2, 2]]]], ys=[[[[3, 4, 4, 3]]]]) show(p)
下面是一个示例,演示如何从三个序列中生成一个带孔的多边形 x 和 y 积分。第一个序列表示多边形的外部,以下序列表示孔:
from bokeh.plotting import figure, output_file, show output_file('multipolygon_with_holes.html') p = figure(plot_width=400, plot_height=400) p.multi_polygons(xs=[[[ [1, 2, 2, 1], [1.2, 1.6, 1.6], [1.8, 1.8, 1.6] ]]], ys=[[[ [3, 3, 4, 4], [3.2, 3.6, 3.2], [3.4, 3.8, 3.8] ]]]) show(p)
有时一个概念多边形是由多个多边形几何图形组成的。下面是一个示例,演示如何从多个 x 和 y 积分。序列中的每一项都代表多重多边形的一部分:
from bokeh.plotting import figure, output_file, show output_file('multipolygon_with_separate_parts.html') p = figure(plot_width=400, plot_height=400) p.multi_polygons(xs=[[[ [1, 1, 2, 2], [1.2, 1.6, 1.6], [1.8, 1.8, 1.6] ], [ [3, 4, 3] ]]], ys=[[[ [4, 3, 3, 4], [3.2, 3.2, 3.6], [3.4, 3.8, 3.8] ], [ [1, 1, 3] ]]]) show(p)
嵌套的顶层用于将每个多多边形与其他多边形分开。每个多重多边形都可以看作是数据源中的一行,可能具有相应的标签或颜色。
from bokeh.plotting import figure, output_file, show output_file('multipolygons.html') p = figure(plot_width=400, plot_height=400) p.multi_polygons( xs=[ [[ [1, 1, 2, 2], [1.2, 1.6, 1.6], [1.8, 1.8, 1.6] ], [ [3, 3, 4] ]], [[ [1, 2, 2, 1], [1.3, 1.3, 1.7, 1.7] ]]], ys=[ [[ [4, 3, 3, 4], [3.2, 3.2, 3.6], [3.4, 3.8, 3.8] ], [ [1, 3, 1] ]], [[ [1, 1, 2, 2], [1.3, 1.7, 1.7, 1.3] ]]], color=['blue', 'red']) show(p)
这个 ellipse() glyph方法接受的属性与 rect() ,但渲染椭圆形状:
ellipse()
from math import pi from bokeh.plotting import figure, output_file, show output_file('ellipses.html') p = figure(plot_width=400, plot_height=400) p.ellipse(x=[1, 2, 3], y=[1, 2, 3], width=[0.2, 0.3, 0.1], height=0.3, angle=pi/3, color="#CAB2D6") show(p)
您可以使用 image() , image_rgba() 和 image_url() 方法。可以使用带有图像标志符号的悬停工具来交互式检查任何像素的值。有关如何启用图像悬停的详细信息,请参阅 Image Hover section 用户指南的。
image()
image_rgba()
image_url()
这里的第一个示例演示如何使用 image_rgba() :
import numpy as np from bokeh.plotting import figure, output_file, show # create an array of RGBA data N = 20 img = np.empty((N, N), dtype=np.uint32) view = img.view(dtype=np.uint8).reshape((N, N, 4)) for i in range(N): for j in range(N): view[i, j, 0] = int(255 * i / N) view[i, j, 1] = 158 view[i, j, 2] = int(255 * j / N) view[i, j, 3] = 255 output_file("image_rgba.html") p = figure(plot_width=400, plot_height=400, x_range=(0, 10), y_range=(0, 10)) p.image_rgba(image=[img], x=[0], y=[0], dw=[10], dh=[10]) show(p)
也可以提供 标量值 ,并使用 image() 字形法。下一个示例演示如何执行此操作:
import numpy as np from bokeh.plotting import figure, output_file, show output_file("image.html", title="image.py example") x = np.linspace(0, 10, 250) y = np.linspace(0, 10, 250) xx, yy = np.meshgrid(x, y) d = np.sin(xx)*np.cos(yy) p = figure(plot_width=400, plot_height=400) p.x_range.range_padding = p.y_range.range_padding = 0 p.image(image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11", level="image") p.grid.grid_line_width = 0.5 show(p)
还要注意,在上面的示例中,我们将渲染级别设置为 "image" . 通常,绘制所有字形 在上面 网格线,但是设置 "image" 渲染级别可用于绘制 在下面 网格线。
"image"
有时,能够同时绘制多个单独的线段是很有用的。Bokeh提供 segment() 和 ray() 用于呈现这些的glyph方法。
segment()
ray()
这个 segment() 函数接受起点 x0 , y0 和终点 x1 和 y1 并渲染以下对象之间的分段:
x0
y0
x1
y1
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.segment(x0=[1, 2, 3], y0=[1, 2, 3], x1=[1.2, 2.4, 3.1], y1=[1.2, 2.5, 3.7], color="#F4A582", line_width=3) show(p)
这个 ray() 函数接受起点 x , y 用一个 length 中 screen units )还有一个 angle .违约 angle_units 是 "rad" 但也可以改为 "deg" . 要获得始终延伸到绘图边缘的“无限”光线,请指定 0 长度:
length
angle_units
"rad"
"deg"
0
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.ray(x=[1, 2, 3], y=[1, 2, 3], length=45, angle=[30, 45, 60], angle_units="deg", color="#FB8072", line_width=2) show(p)
为了绘制一个简单的直线弧,Bokeh提供了 arc() glyph方法,它接受 radius , start_angle 和 end_angle 确定位置。此外 direction 属性确定是否顺时针呈现 ("clock" )或逆时针方向 ("anticlock" )在起始角和结束角之间。
arc()
start_angle
end_angle
direction
"clock"
"anticlock"
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.arc(x=[1, 2, 3], y=[1, 2, 3], radius=0.1, start_angle=0.4, end_angle=4.8, color="navy") show(p)
这个 wedge() glyph方法接受的属性与 arc() ,但会渲染填充的楔体:
wedge()
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.wedge(x=[1, 2, 3], y=[1, 2, 3], radius=0.2, start_angle=0.4, end_angle=4.8, color="firebrick", alpha=0.6, direction="clock") show(p)
The annular_wedge() glyph method is similar to arc(), but draws a filled area. It accepts an inner_radius and outer_radius instead of just radius:
annular_wedge()
inner_radius
outer_radius
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.annular_wedge(x=[1, 2, 3], y=[1, 2, 3], inner_radius=0.1, outer_radius=0.25, start_angle=0.4, end_angle=4.8, color="green", alpha=0.6) show(p)
最后, annulus() glyph方法,它接受 inner_radius 和 outer_radius ,可用于绘制填充环:
annulus()
from bokeh.plotting import figure, show p = figure(plot_width=400, plot_height=400) p.annulus(x=[1, 2, 3], y=[1, 2, 3], inner_radius=0.1, outer_radius=0.25, color="orange", alpha=0.6) show(p)
Bokeh还提供 quadratic() 和 bezier() 绘制参数化二次曲线和三次曲线的字形方法。这有些不常见;请参考 reference documentation 有关详细信息。
quadratic()
bezier()
在一个绘图上组合多个glyph是一个调用多个glyph方法的问题 Figure :
from bokeh.plotting import figure, output_file, show x = [1, 2, 3, 4, 5] y = [6, 7, 8, 7, 3] output_file("multiple.html") p = figure(plot_width=400, plot_height=400) # add both a line and circles on the same plot p.line(x, y, line_width=2) p.circle(x, y, fill_color="white", size=8) show(p)
此原则一般适用于中的所有glyph方法|博克。绘图|. 一个Bokeh图可以添加任意数量的字形。
默认情况下,Bokeh将尝试自动设置绘图的数据边界,使其与数据紧密匹配。有时,可能需要显式设置绘图的范围。这可以通过设置 x_range 或 y_range 使用 Range1d 对象 开始 和 end 所需范围内的点:
x_range
y_range
Range1d
p.x_range = Range1d(0, 100)
为了方便起见, figure() 函数也可以接受 (开始、结束) 作为 x_range 或 y_range 参数。下面的示例显示了两种设置范围的方法:
figure()
from bokeh.models import Range1d from bokeh.plotting import figure, output_file, show output_file("title.html") # create a new plot with a range set with a tuple p = figure(plot_width=400, plot_height=400, x_range=(0, 20)) # set a range using a Range1d p.y_range = Range1d(0, 15) p.circle([1, 2, 3, 4, 5], [2, 5, 8, 2, 7], size=10) show(p)
范围也有一个 bounds 属性,该属性允许您指定不希望用户平移/缩放的绘图限制。
bounds
# set a range using a Range1d p.y_range = Range1d(0, 15, bounds=(0, None))
上面的所有示例都使用默认的线性轴。该轴适用于许多需要以线性比例显示数值数据的绘图。在其他情况下,您可能有分类数据,或者需要以日期时间或日志刻度显示数字数据。本节介绍如何在使用时指定轴类型|博克。绘图|接口。
通过指定 FactorRange 对于其中一个绘图范围(或要转换为一个的系数列表)。下面是一个简单的示例,有关完整的详细信息,请参见 处理分类数据 .
FactorRange
from bokeh.plotting import figure, output_file, show factors = ["a", "b", "c", "d", "e", "f", "g", "h"] x = [50, 40, 65, 10, 25, 37, 80, 60] output_file("categorical.html") p = figure(y_range=factors) p.circle(x, factors, size=15, fill_color="orange", line_color="green", line_width=3) show(p)
当处理timeseries数据或任何涉及日期或时间的数据时,最好有一个轴来显示适合不同日期和时间刻度的标签。
这个例子需要一个网络连接,并且依赖于开源Pandas库,以便更容易地呈现真实的timeseries数据。
我们已经了解了如何使用 figure() 函数来使用|博克。绘图|接口。此函数接受 x_axis_type 和 y_axis_type 作为论据。要指定日期时间轴,请传递 "datetime" 对于这些参数的值。
x_axis_type
y_axis_type
"datetime"
import pandas as pd from bokeh.plotting import figure, output_file, show from bokeh.sampledata.stocks import AAPL df = pd.DataFrame(AAPL) df['date'] = pd.to_datetime(df['date']) output_file("datetime.html") # create a new plot with a datetime axis type p = figure(plot_width=800, plot_height=250, x_axis_type="datetime") p.line(df['date'], df['close'], color='navy', alpha=0.5) show(p)
Bokeh的未来版本将尝试在日期时间轴合适时自动检测情况,并在默认情况下自动添加它们。
当处理指数级增长或多个数量级的数据时,通常需要在对数刻度上有一个轴。另一个场景涉及绘制具有幂律关系的数据,当需要在两个轴上使用对数刻度时。
正如我们在上面看到的 figure() 函数接受 x_axis_type 和 y_axis_type 作为论据。要指定对数轴,请通过 "log" 对于这些参数的值。
"log"
默认情况下,计算对数轴范围以适应正值数据。要设置自己的范围,请参见 设定范围 .
from bokeh.plotting import figure, output_file, show x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] y = [10**xx for xx in x] output_file("log.html") # create a new plot with a log axis type p = figure(plot_width=400, plot_height=400, y_axis_type="log") p.line(x, y, line_width=2) p.circle(x, y, fill_color="white", size=8) show(p)
可以将代表不同范围的多个轴添加到单个绘图中。为此,请在 extra_x_range 和 extra_y_range 属性。然后在添加新的glyph方法时可以引用这些命名范围,也可以使用 add_layout 方法对 Plot . 示例如下:
extra_x_range
extra_y_range
add_layout
Plot
from numpy import arange, linspace, pi, sin from bokeh.models import LinearAxis, Range1d from bokeh.plotting import figure, output_file, show x = arange(-2*pi, 2*pi, 0.1) y = sin(x) y2 = linspace(0, 100, len(y)) output_file("twin_axis.html") p = figure(x_range=(-6.5, 6.5), y_range=(-1.1, 1.1)) p.circle(x, y, color="red") p.extra_y_ranges = {"foo": Range1d(start=0, end=100)} p.circle(x, y2, color="blue", y_range_name="foo") p.add_layout(LinearAxis(y_range_name="foo"), 'left') show(p)