問題描述
如何在散點圖(地理地圖)上標註數據? (How to annotate data on the scatter plot (geo map)?)
來自 california house dataframe (ch),
我創建了這個代碼:
lat, lon = ch['latitude'], ch['longitude']
mhv = ch['median_house_value']
# Scatter the points, using size and color but no label
plt.figure(figsize=(10,7))
plt.scatter(
lon, lat,
c=mhv,
s=ch['population']/100,
linewidth=0, alpha=0.9,
)
plt.xlabel('longitude')
plt.ylabel('latitude')
plt.colorbar(label='median house value')
for pop in [5, 10, 50, 100, 200]:
plt.scatter([], [], alpha=0.6, s=pop,
label=str(pop), c='k')
plt.legend(scatterpoints=1, frameon=False,
labelspacing=1, title='population size* 10e‑2')
plt.show()
問題是:如何在地圖上標註箭頭和括號以及緯度和經度的最小和最大坐標?
換句話說:我想要這個 ‑ ‑>(min lat, min lon) 和 ‑‑>(max lat, max lon) 在地圖上標記點。
參考解法
方法 1:
I think your data is from Kaggle, but I do not have it. Anyway, maybe you can try these:
# add text at bottom left
x,y = (‑123,33)
plt.text(x,y,'(min lat, min lon)',fontsize=20,weight='bold',bbox=dict(facecolor='white', edgecolor='black'))
add arrows (use negative values to reverse the arrow direction)
plt.arrow(x=‑124, y=33, dx=5, dy=0, width=.08, color = "purple")
</code></pre>
Of course, you may adjust the input values based on your needs.
(by Lorenzo Bussotti、Jeremy)
參考文件