始める無料で始める

可読性を高める

あなたと同僚は、見せたいデータで最も重要なのは、最も「市場に優しい」州であるVermontと、最もそうでないTexasの違いだと判断しました。これを示すために、2つのプロットを横に並べて表示します。1つは各州のファーマーズマーケットあたりの人数を示す棒グラフ、もう1つはx軸に人口、y軸にマーケット数をとった散布図です。

VermontとTexasをそれぞれ異なる色で強調して、結果を際立たせましょう。さらに、Texasについては大きく読みやすい注釈も追加します。

VermontとTexasに固有の色を割り当て、他の州は灰色にするベクトル state_colors と、Texasを説明する注釈 tx_message が用意されています。

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

Pythonでデータ可視化を磨く

コースを見る

演習の手順

  • 提供された色ベクトル state_colors を、sns.barplot()palette 引数で棒グラフ(ax1)に適用します。
  • 散布図の点には、引数 c で色ベクトルを指定します。
  • 注釈テキストのサイズを 15 に変更して、読みやすくしてください。

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

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

# Draw barplot w/ colors mapped to state_colors vector
sns.barplot('people_per_market', 'state', ____ = ____,
            data = markets_by_state, ax = ax1)

# Map state colors vector to the scatterplot as well
p = sns.scatterplot('population', 'num_markets', c = ____,
                    data = markets_by_state, s = 60, ax = ax2)

# Log the x and y scales of our scatter plot so it's easier to read
ax2.set(xscale = "____", yscale = '____')

# Increase annotation text size for legibility
ax2.annotate(tx_message, xy = (26956958,230), 
             xytext = (26956958, 450),ha = 'right', 
             size = ____, backgroundcolor = 'white',
             arrowprops = {'facecolor':'black', 'width': 3})
sns.set_style('whitegrid')
plt.show()
コードを編集して実行