[英]how to make map lines visible over data in cartopy?
I am trying to make map lines always on top of data, but cannot find the right command/options to do so in cartopy.我正在尝试使 map 行始终位于数据之上,但在 cartopy 中找不到正确的命令/选项。 In the plot below, I want the thick blue line "under" the black state lines but on top of the beige states.
在下面的 plot 中,我想要在黑色 state 线“下方”但在米色状态之上的粗蓝线。
Code:代码:
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import os,sys
conus_proj = ccrs.LambertConformal(central_longitude=-96,central_latitude=39.0)
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(1,1,1,projection=conus_proj)
ax.set_extent([-120,-70,22,50])
#ax.add_feature(cfeature.BORDERS)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.OCEAN, facecolor='#CCFEFF')
ax.add_feature(cfeature.LAKES, facecolor='#CCFEFF')
ax.add_feature(cfeature.RIVERS, facecolor='#CCFEFF')
ax.add_feature(cfeature.LAND, facecolor='#FFE9B5')
state_borders = cfeature.NaturalEarthFeature(category='cultural', name='admin_1_states_provinces_lakes', scale='50m', facecolor='#FFE9B5')
ax.add_feature(state_borders, edgecolor='black')
plt.plot([-120,-70],[35,45],linewidth=8, transform=ccrs.PlateCarree())
plt.show()
I have tried changing the zorder of ax.add_feature(state_borders...)
and plt.plot(...)
but have received weird results.我尝试更改
ax.add_feature(state_borders...)
和plt.plot(...)
的 zorder,但收到了奇怪的结果。 The state borders are on top by default with pcolormesh
, but don't appear to be so with plt.plot
state 边框默认使用
pcolormesh
位于顶部,但plt.plot
似乎并非如此
The reason things turn out differently for pcolormesh
vs. plot
is that those have different default zorders. pcolormesh
与plot
的结果不同的原因是它们具有不同的默认 zorder。 If I set the zorder for the state borders (note below that I use Cartopy's built-in support for states) to 10, I get them to appear on top of the plot:如果我将 state 边框的 zorder (请注意下面我使用 Cartopy 对状态的内置支持)设置为 10,我会让它们出现在 plot 的顶部:
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import os,sys
conus_proj = ccrs.LambertConformal(central_longitude=-96,central_latitude=39.0)
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(1,1,1,projection=conus_proj)
ax.set_extent([-120,-70,22,50])
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.OCEAN, facecolor='#CCFEFF')
ax.add_feature(cfeature.LAKES, facecolor='#CCFEFF')
ax.add_feature(cfeature.RIVERS, edgecolor='#CCFEFF')
ax.add_feature(cfeature.LAND, facecolor='#FFE9B5')
ax.add_feature(cfeature.STATES, edgecolor='black', zorder=10)
plt.plot([-120,-70],[35,45],linewidth=8, transform=ccrs.PlateCarree())
plt.show()
I also had to remove the face colors on some of the features.我还不得不在某些功能上删除面部 colors。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.