您好,整天都在尝试这样做! 我已经使用底图创建了一个地图,并且尝试绘制CSV文件中的所有纬度和经度位置。有什么想法或提示吗? 这是csv文件的图片
def map_test():
col_list = ["longitude", "latitude"]
dataset = pd.read_csv('charge_point_registry.csv', usecols=col_list)
latitudes = dataset.loc[:, 'latitude']
longitudes = dataset.loc[:, 'longitude']
# Creates a base map ready for attributes
plt.figure(figsize=(20, 15))
m = Basemap(projection='mill',
# coordinates of a box to contain map of UK
llcrnrlat=48.632909,
llcrnrlon=-14.452873,
urcrnrlon=3.136989,
urcrnrlat=61.648162,
# quality of map
resolution='l')
m.drawcoastlines()
m.drawcounties()
m.fillcontinents(color = "green")
geometry = [Point(xy) for xy in zip(longitudes, latitudes)]
gdf = GeoDataFrame(dataset, geometry=geometry)
gdf.plot(ax=m.plot(figsize=(20, 15)), marker='o', color='red', markersize=15)
# m.bluemarble()
plt.show()
谢谢:)
答案 0 :(得分:2)
不推荐使用Matplotlib底图,而推荐使用Cartopy。这是一些代码,可让您绘制英国数据。
import numpy as np
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import pandas as pd
long_list = np.arange(-179.5, 180, 1)
lat_list = np.arange(-89.5, 90, 1)
value_dict = {'latitude':[51.0, 51.2, 53.4, 54.5],
'longitude':[-1.1, -1.3, -0.2, -0.9]}
#replace this with your df
df = pd.DataFrame(value_dict)
proj = ccrs.PlateCarree(central_longitude=0)
fig, ax = plt.subplots(subplot_kw=dict(projection=proj), figsize=(16,16))
ax.set_extent([-10, 3, 48, 61], crs=ccrs.PlateCarree())
fig.canvas.draw()
fig.tight_layout()
ax.add_feature(cfeature.LAND, facecolor='0.25')
ax.add_feature(cfeature.BORDERS, zorder=10)
ax.scatter(df['longitude'].values.tolist(), df['latitude'].values.tolist())
gl = ax.gridlines(crs=proj, draw_labels=False, alpha=1, linewidth=0.25)
gl.xlocator = mticker.FixedLocator(long_list)
gl.ylocator = mticker.FixedLocator(lat_list)
plt.show()