开始使用免费开始使用

添加颜色条

机构希望您添加一个 ColorBar,以便查看图表的人能理解图元颜色变化所对应的阈值。

上一个练习中的图形对象、mapper 和图元都已为您准备好。

本练习是课程的一部分

使用 Bokeh 进行交互式数据可视化

查看课程

练习说明

  • 导入 ColorBar
  • 使用 mapper 中的相关键创建 color_bar,并将宽度设置为 8 像素。
  • color_bar 添加到图形右侧的布局中。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import ColorBar
____

mapper = linear_cmap(field_name="assists", palette=RdBu8, low=min(nba["assists"]), high=max(nba["assists"]))
fig = figure(x_axis_label="Steals", y_axis_label="Assists", title="Steals vs. Assists")
fig.circle(x="steals", y="assists", source=source, color=mapper)

# Create the color_bar
color_bar = ____(color_mapper=____, width=____)

# Update layout with color_bar on the right
fig.____(____, "____")
output_file(filename="steals_vs_assists_color_mapped.html")
show(fig)
编辑并运行代码