gridplot を使う
不動産エージェントは、メルボルンの4つの地域(
"Northern"、"Western"、"Eastern"、"Southern")で、物件の広さと価格の関係がどのように異なるかを確認したいと考えています。
各地域ごとに 1 つのサブプロットを表示する gridplot を使う絶好の機会です!
この演習はコースの一部です
Bokehで学ぶインタラクティブ・データビジュアライゼーション
演習の手順
gridplotをインポートします。- 目的の地域で
melbをフィルタリングしてdfを作成します。 figに円のグリフを追加するコードを完成させます。sourceから、建物面積の列をx、価格をy、legend_labelをregionとして指定します。- 2 列のグリッドでサブプロットを表示します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import gridplot
from ____.____ import ____
plots = []
# Complete for loop to create plots
for region in ["Northern", "Western", "Southern", "Eastern"]:
df = melb.loc[melb["region"] == ____]
source = ColumnDataSource(data=df)
fig = figure(x_axis_label="Building Area (Meters Squared)", y_axis_label="Price")
fig.circle(x="____", y="____", source=____, legend_label=____)
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0a")
plots.append(fig)
# Display plot
output_file(filename="gridplot.html")
show(____(____, ncols=____))