我正在尝试在法国地图上绘制一次旅行,但我不能只绘制法国地图(见图),有人可以帮我吗?我相信这可能是上下文库中的 crs 的问题,但我没有在网上找到任何信息这是一个可重现的示例...
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import shapely
import matplotlib.pyplot as plt
from matplotlib.colors import to_hex
import seaborn as sns
import contextily as ctx
def main():
gdf = pd.DataFrame()
gdf["longitudes"] = [5.8127891, 5.2250324]
gdf["latitudes"] = [46.1965678, 46.2051192]
gdf["geometry"] = gpd.points_from_xy(gdf["longitudes"], gdf["latitudes"])
gdf = gpd.GeoDataFrame(gdf, crs= {"init": "epsg:4326"})
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
france = world.query('name == "France"')
# Make the plot
fig, ax = plt.subplots(figsize=(4,5))
#ax = gdf.plot(figsize=(10, 5))
# Plot the state outlines
france.boundary.plot(color='black', linewidth=0.5, ax=ax)
# Modify projection to match what contextily uses
gdf = gdf.to_crs(epsg=3857)
part1 = shapely.geometry.LineString(
gdf['geometry'].values)
linegdf = gpd.GeoDataFrame(
{'geometry': [part1]}
)
c = to_hex(sns.light_palette('green')[0])
linegdf.plot(
color=c,
linewidth=3,
ax=ax
)
print(len(gdf))
# Plot points colored by day
gdf.plot(
cmap=sns.light_palette('green', as_cmap=True),
ax=ax,
markersize=50,
edgecolor='black', linewidth=0.5,
zorder=1000 # force the points to be the top layer of the plot
)
# Add basemap
ctx.add_basemap(ax=ax)
# Remove axes
ax.set_axis_off()
plt.show()
main()
任何帮助深表感谢 !