颜色、图例与主题
在第一个任务中,中介机构希望看到一幅可视化图,展示房屋建造年份与其总土地面积之间的关系,并区分墨尔本北部与南部区域的差异。您决定为该图使用 Bokeh 的自定义主题之一。
已经根据房产所在的 region 将 melb 分成两个子集 north 和 south,如下所示:
north = melb.loc[melb["region"] == "Northern"]
south = melb.loc[melb["region"] == "Southern"]
已经为您预加载了一个图形 fig。您将更新主题,并为每个区域使用不同颜色添加圆形图元。随后,添加 legend_label 以便清晰区分。
本练习是课程的一部分
使用 Bokeh 进行交互式数据可视化
练习说明
- 导入
curdoc。 - 将主题更新为
"contrast"。 - 为
north添加圆形图元,分别将x和y设为year_built与land_area,将color设为"yellow",legend_label设为"North"。 - 对
south重复上述操作,将color设为"red",legend_label设为"South"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import curdoc
from ____.____ import ____
# Change theme to contrast
____().____ = "____"
fig = figure(x_axis_label="Year Built", y_axis_label="Land Area (Meters Squared)")
# Add north circle glyphs
fig.circle(x=north["____"], y=north["____"], color="____", legend_label="____")
# Add south circle glyphs
fig.____(____=____, ____=____, ____="____", legend_label="____")
output_file(filename="north_vs_south.html")
show(fig)