如何在底图中显示每个散点的标签?
How to show the labels of each scatter point in a basemap?
这是我的代码:
fig = plt.figure(figsize=(12, 8), dpi=300)
m = Basemap(width=20000,height=15000,resolution='c',projection='lcc',lon_0=-0.09,lat_0=51.49)
m.drawcoastlines(linewidth=0.5)
m.fillcontinents(color='tan',lake_color='lightblue')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,15.),labels=[True,True,False,False],dashes=[2,2])
m.drawmeridians(np.arange(-180.,181.,15.),labels=[False,False,False,True],dashes=[2,2])
m.drawmapboundary(fill_color='lightblue')
m.drawcountries(linewidth=2, linestyle='solid', color='k' )
m.drawstates(linewidth=0.5, linestyle='solid', color='k')
#m.drawrivers(linewidth=0.5, linestyle='solid', color='blue')
x, y = m(df2['lon'].values, df2['lat'].values)
m.scatter(x,y, marker="*", color='b', alpha=0.7, zorder=5, s=9)
plt.title("Localización de los Bikepoints", fontsize=14)
plt.xlabel('Longitud', fontsize=10)
plt.ylabel('Latitud', fontsize=10)
plt.show()
这是结果:
如何为每个点添加标签。这些名字在我的数据框的一列中。
我是这样做的:
with plt.style.context('seaborn'): # 'fivethirtyeight'
fig = plt.figure(figsize=(20,8)) ;
for i in range(nd):
x = data_df.loc[i,data_df.columns[1]]
y = data_df.loc[i,data_df.columns[2]]
tx= data_df.loc[i,data_df.columns[0]]
plt.plot(x, y, marker='o',ms=29, c='orange',alpha = 0.6)
plt.text(x,y, tx, fontsize=18)
plt.title('Nobel Laureates vs Chocolate Consumption', fontweight='bold',fontsize=35)
plt.margins(0.1)
plt.show()
完整示例here
我解决了这个问题如下:
for i in range(df.shape[0]):
x = df['lon'][i]
y = df['lat'][i]
tx= df['location'][i]
xx, yy = m(x, y) #m is basemap object
plt.text(xx,yy, tx, fontsize=12)
其中:
m = Basemap(projection='lcc', resolution='l',
lat_0=40.01, lon_0=-1.52,
width=1.5E6, height=1.1E6)
这是我的代码:
fig = plt.figure(figsize=(12, 8), dpi=300)
m = Basemap(width=20000,height=15000,resolution='c',projection='lcc',lon_0=-0.09,lat_0=51.49)
m.drawcoastlines(linewidth=0.5)
m.fillcontinents(color='tan',lake_color='lightblue')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,15.),labels=[True,True,False,False],dashes=[2,2])
m.drawmeridians(np.arange(-180.,181.,15.),labels=[False,False,False,True],dashes=[2,2])
m.drawmapboundary(fill_color='lightblue')
m.drawcountries(linewidth=2, linestyle='solid', color='k' )
m.drawstates(linewidth=0.5, linestyle='solid', color='k')
#m.drawrivers(linewidth=0.5, linestyle='solid', color='blue')
x, y = m(df2['lon'].values, df2['lat'].values)
m.scatter(x,y, marker="*", color='b', alpha=0.7, zorder=5, s=9)
plt.title("Localización de los Bikepoints", fontsize=14)
plt.xlabel('Longitud', fontsize=10)
plt.ylabel('Latitud', fontsize=10)
plt.show()
这是结果:
如何为每个点添加标签。这些名字在我的数据框的一列中。
我是这样做的:
with plt.style.context('seaborn'): # 'fivethirtyeight'
fig = plt.figure(figsize=(20,8)) ;
for i in range(nd):
x = data_df.loc[i,data_df.columns[1]]
y = data_df.loc[i,data_df.columns[2]]
tx= data_df.loc[i,data_df.columns[0]]
plt.plot(x, y, marker='o',ms=29, c='orange',alpha = 0.6)
plt.text(x,y, tx, fontsize=18)
plt.title('Nobel Laureates vs Chocolate Consumption', fontweight='bold',fontsize=35)
plt.margins(0.1)
plt.show()
完整示例here
我解决了这个问题如下:
for i in range(df.shape[0]):
x = df['lon'][i]
y = df['lat'][i]
tx= df['location'][i]
xx, yy = m(x, y) #m is basemap object
plt.text(xx,yy, tx, fontsize=12)
其中:
m = Basemap(projection='lcc', resolution='l',
lat_0=40.01, lon_0=-1.52,
width=1.5E6, height=1.1E6)