按时间的销售额
房产中介现在请您分析住房市场活动,以可视化总销售额随时间的变化。melb DataFrame 已按 date 分组,这次对 price 列求和来计算总销售额,并存为 melb_sales:
melb_sales = melb.groupby("date", as_index=False)["price"].sum()
已基于 melb_sales 创建 source,并为您预加载。您的任务是格式化图表,使坐标轴信息清晰,从而便于解读可视化结果。
本练习是课程的一部分
使用 Bokeh 进行交互式数据可视化
练习说明
- 导入需要的类,以将坐标轴标签更改为
datetime和numeric格式。 - 向图形添加线图元,从
source中将 x 设为"date",y 设为"price"。 - 将 x 轴刻度格式更新为月份 3 个字符、年份 4 位数字。
- 将 y 轴格式设置为
"$0a",以百万美元显示。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the second formatter
from bokeh.models import ____, ____
fig = figure(x_axis_label="Date", y_axis_label="Sales")
# Add line glyphs
fig.line(____)
# Format the x-axis format
fig.____[____].____ = ____(months="____")
# Format the y-axis format
fig.____[____].____ = ____(format="____")
output_file(filename="melbourne_sales.html")
show(fig)