跨越 lon=180 的缓冲线导致条带化 geopandas matplotlib
Buffer line across lon=180 causes banding geopandas matplotlib
当地图的 central_longitude = 180 时,我正在尝试绘制横跨 180 经度的多边形几何图形;但是会出现人工条带。
有没有办法阻止 matplotlib 出现红色圆圈中显示的条带?
import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs
lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
gdf = gdf.to_crs({'init': 'epsg:3174'})
gdf['geometry'] = gdf['geometry'].buffer(90000)
gdf['route'] = 0
gdf = gdf.to_crs({'init': 'EPSG:4326'})
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf['geometry'], crs=ccrs.PlateCarree())
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()
从 epsg:3174
重新投影到 EPSG:4326
会混淆跨日期变更线的几何图形。您可以直接使用 epsg:3174
绘制地理数据框,如以下代码所示:
import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs
import numpy as np
lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
# gdf2 = gdf.to_crs({'init': 'epsg:3174'})
gdf2 = gdf.to_crs(epsg=3174)
gdf2['geometry'] = gdf2['geometry'].buffer(90000)
gdf2['route'] = 0
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf2['geometry'], crs=ccrs.epsg(3174))
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()
plt.show()
当地图的 central_longitude = 180 时,我正在尝试绘制横跨 180 经度的多边形几何图形;但是会出现人工条带。
有没有办法阻止 matplotlib 出现红色圆圈中显示的条带?
import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs
lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
gdf = gdf.to_crs({'init': 'epsg:3174'})
gdf['geometry'] = gdf['geometry'].buffer(90000)
gdf['route'] = 0
gdf = gdf.to_crs({'init': 'EPSG:4326'})
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf['geometry'], crs=ccrs.PlateCarree())
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()
从 epsg:3174
重新投影到 EPSG:4326
会混淆跨日期变更线的几何图形。您可以直接使用 epsg:3174
绘制地理数据框,如以下代码所示:
import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs
import numpy as np
lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
# gdf2 = gdf.to_crs({'init': 'epsg:3174'})
gdf2 = gdf.to_crs(epsg=3174)
gdf2['geometry'] = gdf2['geometry'].buffer(90000)
gdf2['route'] = 0
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf2['geometry'], crs=ccrs.epsg(3174))
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()
plt.show()