複数レイヤーのプロット
pandas の代表的な機能に、DataFrame のフィルタリング(条件に基づいて行のサブセットを取り出す=ブールマスクの生成)があります。
この演習では、アフリカ料理のレストランだけを抽出し、さらにマルチレイヤーのプロットを作成します。マルチレイヤーのプロットでは、複数の GeoDataFrame を1つの図に重ねて可視化します。レイヤーを追加するには、GeoDataFrame の plot() メソッドで matplotlib の axes オブジェクトを ax キーワード引数として渡します。
レストランのデータは restaurants という GeoDataFrame としてすでに読み込まれています。GeoPandas は geopandas、matplotlib.pyplot は plt としてインポート済みです。
この演習はコースの一部です
Pythonで扱う地理空間データ
演習の手順
typeが 'African restaurant' のすべての行を抽出して、サブセットをafrican_restaurantsと名付けてください。- すべてのレストランを均一なグレーでプロットします。matplotlib の axes オブジェクトを
plot()メソッドに渡すのを忘れないでください。 - 2つ目のレイヤーとして、アフリカ料理のレストランのみを赤で追加します。色は 'red' や 'grey' のような英語名を使えます。
- matplotlib の axes オブジェクトで
set_axis_off()メソッドを使い、枠線を非表示にしてください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Load the restaurants dataset
restaurants = geopandas.read_file("paris_restaurants.geosjon")
# Take a subset of the African restaurants
african_restaurants = ____
# Make a multi-layered plot
fig, ax = plt.subplots(figsize=(10, 10))
restaurants.____
african_restaurants.____
# Remove the box, ticks and labels
ax.____
plt.show()