始める無料で始める

注釈の追加

これまで学んだカスタマイズ機能は、組み合わせて使うことができます。 次の演習では、分布プロットに注釈を加え、家賃の平均値と中央値を示す線を表示してみましょう。

この例では、sns.set_palette() を使ってパレットを bright に変更しています。

この演習はコースの一部です

Seaborn による中級データ可視化

コースを見る

演習の手順

  • figure と axes を作成します。
  • fmr_1 列の分布をプロットします。
  • すでに定義されている medianmean の値に対して、axvline を使って垂直線を追加します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Create a figure and axes. Then plot the data
fig, ax = plt.subplots()
sns.histplot(df['fmr_1'], ax=ax)

# Customize the labels and limits
ax.set(____="1 Bedroom Fair Market Rent", xlim=(100,1500), title="US Rent")

# Add vertical lines for the median and mean
ax.axvline(x=____, color='m', label='Median', linestyle='--', linewidth=2)
ax.axvline(x=____, color='b', label='Mean', linestyle='-', linewidth=2)

# Show the legend and plot the data
ax.____()
plt.show()
コードを編集して実行