Skip to content

Instantly share code, notes, and snippets.

@smzn
Created January 7, 2024 01:00
Show Gist options
  • Save smzn/9257edcb0a77ff5884b124dfa7fd78b3 to your computer and use it in GitHub Desktop.
Save smzn/9257edcb0a77ff5884b124dfa7fd78b3 to your computer and use it in GitHub Desktop.
ステーションの地図表示
import folium
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
# 利用回数に応じた色の設定
def get_color(usage, max_usage):
norm = plt.Normalize(aggregated_data['Total Usage'].min(), max_usage)
cmap = plt.cm.Reds #Reds
rgb = cmap(norm(usage))[:3]
return mcolors.rgb2hex(rgb)
# 最大利用回数を持つステーションの平均緯度・経度を取得
max_usage = aggregated_data['Total Usage'].max()
max_usage_lat = aggregated_data.loc[aggregated_data['Total Usage'].idxmax(), 'Average Latitude']
max_usage_lng = aggregated_data.loc[aggregated_data['Total Usage'].idxmax(), 'Average Longitude']
# 地図の初期化
m = folium.Map(location=[max_usage_lat, max_usage_lng], zoom_start=12)
# 各ステーションのマーカーを追加
for idx, row in aggregated_data.iterrows():
color = get_color(row['Total Usage'], max_usage)
folium.CircleMarker(
location=[row['Average Latitude'], row['Average Longitude']],
radius=5, # 固定サイズ
popup=f'{idx}<br>Usage: {row["Total Usage"]}',
color=color,
fill=True,
fill_color=color
).add_to(m)
# 地図を表示
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment