如何在散點圖(地理地圖)上標註數據? (How to annotate data on the scatter plot (geo map)?)


問題描述

如何在散點圖(地理地圖)上標註數據? (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 BussottiJeremy)

參考文件

  1. How to annotate data on the scatter plot (geo map)? (CC BY‑SA 2.5/3.0/4.0)

#scatter-plot #Python #python-3.x #matplotlib #pandas






相關問題

matplotlib:重繪前清除散點數據 (matplotlib: clearing the scatter data before redrawing)

使用 matplotlib 保存散點圖動畫 (Saving scatterplot animations with matplotlib)

在 matplotlib 中圍繞散點圖中的數據點繪製平滑多邊形 (draw a smooth polygon around data points in a scatter plot, in matplotlib)

Java:非常簡單的散點圖實用程序 (Java: Really simple scatter plot utility)

如何在多個圖中選擇一個要編輯的圖? (How to select one plot to be edit in multiple plots?)

d3js散點圖自動更新不起作用 (d3js scatter plot auto update doesnt work)

散點圖中的重疊趨勢線,R (Overlapping Trend Lines in scatterplots, R)

DC.JS 散點圖選擇 (DC.JS scatterplot chart selection)

固定散景散點圖中的軸間距(刻度) (Fixing axis spacing (ticks) in Bokeh scatter plots)

如何在顏色條上繪製散點圖? (How to plot scatter plot points on a colorbar?)

如何在散點圖中以均勻間隔更改 x 軸值? (How to change x axis value with even interval in scatter plot?)

如何在散點圖(地理地圖)上標註數據? (How to annotate data on the scatter plot (geo map)?)







留言討論