即使设置了填充颜色,cartopy 也不会填充国家/地区
cartopy doesnt fill country even though fillcolor is set
我想用红色填充一个国家来突出显示它。但是,当我这样做时,会遵循以下示例:https://matthewkudija.com/blog/2018/05/25/country-maps/
没用。相反,它只是绘制原始颜色。它似乎只有在我使用 PlateCarree
投影时才有效。
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 10))
proj = ccrs.Orthographic(50, 30)
ax = plt.axes(projection=proj)
ax.add_feature(cartopy.feature.OCEAN, zorder=0)
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')
ax.set_global()
ax.gridlines()
ax.add_feature(cartopy.feature.BORDERS, linestyle=':', alpha=1)
shpfilename = shpreader.natural_earth(resolution='110m',
category='cultural',
name='admin_0_countries')
reader = shpreader.Reader(shpfilename)
countries = reader.records()
for country in countries:
if country.attributes['ADM0_A3'] == 'OMN':
break
ax.add_geometries(country.geometry, proj,
# facecolor=(1, 0, 0),
facecolor='red',
# label=country.attributes['adm0_a3'])
label=country.attributes['ADM0_A3']
,zorder=20)
是否有特定原因需要将 crs 设置为正字法?正如你所说,代码 运行 成功地为我使用
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 10))
proj = ccrs.Orthographic(50, 30)
ax = plt.axes(projection=proj)
ax.add_feature(cartopy.feature.OCEAN, zorder=0)
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')
ax.set_global()
ax.gridlines()
ax.add_feature(cartopy.feature.BORDERS, linestyle=':', alpha=1)
shpfilename = shpreader.natural_earth(resolution='110m',
category='cultural',
name='admin_0_countries')
reader = shpreader.Reader(shpfilename)
countries = reader.records()
for country in countries:
if country.attributes['ADM0_A3'] == 'OMN':
ax.add_geometries(country.geometry, ccrs.PlateCarree(), facecolor='red')
我想用红色填充一个国家来突出显示它。但是,当我这样做时,会遵循以下示例:https://matthewkudija.com/blog/2018/05/25/country-maps/
没用。相反,它只是绘制原始颜色。它似乎只有在我使用 PlateCarree
投影时才有效。
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 10))
proj = ccrs.Orthographic(50, 30)
ax = plt.axes(projection=proj)
ax.add_feature(cartopy.feature.OCEAN, zorder=0)
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')
ax.set_global()
ax.gridlines()
ax.add_feature(cartopy.feature.BORDERS, linestyle=':', alpha=1)
shpfilename = shpreader.natural_earth(resolution='110m',
category='cultural',
name='admin_0_countries')
reader = shpreader.Reader(shpfilename)
countries = reader.records()
for country in countries:
if country.attributes['ADM0_A3'] == 'OMN':
break
ax.add_geometries(country.geometry, proj,
# facecolor=(1, 0, 0),
facecolor='red',
# label=country.attributes['adm0_a3'])
label=country.attributes['ADM0_A3']
,zorder=20)
是否有特定原因需要将 crs 设置为正字法?正如你所说,代码 运行 成功地为我使用
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 10))
proj = ccrs.Orthographic(50, 30)
ax = plt.axes(projection=proj)
ax.add_feature(cartopy.feature.OCEAN, zorder=0)
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')
ax.set_global()
ax.gridlines()
ax.add_feature(cartopy.feature.BORDERS, linestyle=':', alpha=1)
shpfilename = shpreader.natural_earth(resolution='110m',
category='cultural',
name='admin_0_countries')
reader = shpreader.Reader(shpfilename)
countries = reader.records()
for country in countries:
if country.attributes['ADM0_A3'] == 'OMN':
ax.add_geometries(country.geometry, ccrs.PlateCarree(), facecolor='red')