小编Adm*_*med的帖子

散景将图例添加到步骤图

如何为散景的步骤图示例中的线条添加图例:

https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/step.html

我想在情节的“右上角”为每条线的颜色和线条样式添加图例。

该示例的默认代码是:

import numpy as np


from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid

from bokeh.models.glyphs import Step

from bokeh.io import curdoc, show


N = 11

x = np.linspace(-2, 2, N)
y = x**2

source = ColumnDataSource(dict(x=x, y1=y, y2=y+2, y3=y+4))

xdr = DataRange1d()
ydr = DataRange1d()

plot = Plot(
    title=None, x_range=xdr, y_range=ydr, plot_width=300, plot_height=300,
    h_symmetry=False, v_symmetry=False, min_border=0,toolbar_location=None)

glyph1 = Step(x="x", y="y1", line_color="#f46d43", mode="before")
plot.add_glyph(source, glyph1)

glyph2 = Step(x="x", y="y2", line_dash="dashed", line_color="#1d91d0", mode="center")
plot.add_glyph(source, glyph2)

glyph3 = Step(x="x", y="y3", …
Run Code Online (Sandbox Code Playgroud)

python plot legend python-3.x bokeh

2
推荐指数
1
解决办法
6291
查看次数

标签 统计

bokeh ×1

legend ×1

plot ×1

python ×1

python-3.x ×1