【发布时间】:2021-03-22 12:38:28
【问题描述】:
我有一个包含一些城市信息的 excel 文件,现在我想在地图上标出这些城市的名称。我编写了以下代码,但是,我无法正确获取引用的名称。对于每个引用,我都会得到一个带有“名称”整个列表的标签。欢迎提出任何建议。
#我无法安装 PyGMT 或底图甚至 geopandas,所以我只有 cartopy。
import pandas as pd
import csv
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
df = pd.read_excel('./seismogram.xlsx')
lon = df['longitude'].to_list()
lat = df['latitude '].to_list()
name = (df['code']).to_list()
def main():
fig = plt.figure(figsize=(15,15))
plt.rcParams["font.size"] = 18
ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree())
ax.set_extent([128, 133, 30, 35], crs=ccrs.PlateCarree())
ax.set_title("Japan")
ax.coastlines(resolution='10m')
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.stock_img()
return fig, ax
fig, ax = main()
ax.scatter(lon, lat, color="r", marker="o", s = 15)
zip_object = zip(lon, lat, name)
for (lg, lt, ne) in zip_object:
ax.text(lg - .05, lt + .05,
name,
va='center',
ha='right', transform=ccrs.Geodetic(), fontweight='bold')
plt.show()
【问题讨论】:
-
有什么问题?请出示您获得的地块。
标签: python excel pandas dictionary cartopy