具有LCC投影的Cartopy纬度/经度标签

时间:2019-06-13 17:03:28

标签: python matplotlib plot mapping cartopy

我需要在LCC投影图中添加纬度/经度标签。事实证明这是如此复杂。我使用了代码here,它对于单个面板图形确实非常有效。不幸的是,我的数字都需要为3-4个面板。 2个问题。

  1. 子图1上的锚定文本(假定为“ a”)消失了。

  2. 奇怪的文本出现在子图2-3上,我无法确定是什么生成的。

一如既往的感谢!

我的代码:

fig = plt.figure(1,figsize=(11,9), dpi=600.0)
projection = ccrs.LambertConformal(central_longitude=-105,central_latitude=45,standard_parallels=[50,40])

ax1 = fig.add_subplot(131, projection = projection)

test = plt.contourf(temp.lon,temp.lat,temp[:,:].values,transform=ccrs.PlateCarree(),levels=levs,cmap='RdBu_r', extend='both')
plt.contourf(temp_pval.lon,temp_pval.lat,temp_pval[:,:].values,transform=ccrs.PlateCarree(),color='none',edgecolor='black',hatches="..",alpha=0.,add_colorbar = False)

ax1.set_extent([ext_e, ext_w, ext_s, ext_n])
states_provinces = cfeature.NaturalEarthFeature(
    category='cultural',
    name='admin_1_states_provinces_lines',
    scale='50m',
    facecolor='none')
ax1.add_feature(states_provinces, edgecolor='black', linewidth=0.2)
ax1.add_feature(cfeature.COASTLINE)
ax1.add_feature(cfeature.BORDERS)
shape_feature = ShapelyFeature(Reader('/Users/gbromley/Dropbox/Montana_Climate_Project/Study_Area/NGP_Study_Area/Study_Area_08_01_17.shp').geometries(),crs=ccrs.PlateCarree(), facecolor='none',edgecolor='black')
ax1.add_feature(shape_feature)


# *must* call draw in order to get the axis boundary used to add ticks:
fig.canvas.draw()

# Define gridline locations and draw the lines using cartopy's built-in gridliner:
xticks = [-120,-110, -100, -90]
yticks = [30, 40, 50, 60]
ax1.gridlines(xlocs=xticks, ylocs=yticks)

# Label the end-points of the gridlines using the custom tick makers:
ax1.xaxis.set_major_formatter(LONGITUDE_FORMATTER) 
ax1.yaxis.set_major_formatter(LATITUDE_FORMATTER)
pf.lambert_xticks(ax1, xticks)
pf.lambert_yticks(ax1, yticks)

ax1.title.set_visible(False)
cb = plt.colorbar(test, cmap='RdBu_r',fraction=0.037)
cb.set_label('$^\circ$C / Decade',fontsize=10)

anchored_text = AnchoredText("a", loc=2)

### VPD Plot ###
ax2 = fig.add_subplot(132, projection = projection)

test2 = plt.contourf(vpd.lon,vpd.lat,vpd[:,:].values,transform=ccrs.PlateCarree(),levels=levs,cmap='PuOr_r', extend='both')

ax2.set_extent([ext_e, ext_w, ext_s, ext_n])
states_provinces = cfeature.NaturalEarthFeature(
    category='cultural',
    name='admin_1_states_provinces_lines',
    scale='50m',
    facecolor='none')
ax2.add_feature(states_provinces, edgecolor='lightgray')
ax2.add_feature(cfeature.COASTLINE)
ax2.add_feature(cfeature.BORDERS)
vpd_pval.plot.contourf(axes=ax2,transform=ccrs.PlateCarree(),color='none',edgecolor='black',hatches="..",alpha=0.,add_colorbar = False)


shape_feature = ShapelyFeature(Reader('/Users/gbromley/Dropbox/Montana_Climate_Project/Study_Area/NGP_Study_Area/Study_Area_08_01_17.shp').geometries(),crs=ccrs.PlateCarree(), facecolor='none',edgecolor='black')
ax2.add_feature(shape_feature)


# *must* call draw in order to get the axis boundary used to add ticks:
fig.canvas.draw()

# Define gridline locations and draw the lines using cartopy's built-in gridliner:
xticks = [-120,-110, -100, -90]
yticks = [30, 40, 50, 60]
ax2.gridlines(xlocs=xticks, ylocs=yticks)

# Label the end-points of the gridlines using the custom tick makers:
ax2.xaxis.set_major_formatter(LONGITUDE_FORMATTER) 
ax2.yaxis.set_major_formatter(LATITUDE_FORMATTER)
pf.lambert_xticks(ax2, xticks)
pf.lambert_yticks(ax2, yticks)


ax2.title.set_visible(False)
cb = plt.colorbar(test2, cmap='PuOr_r',fraction=0.037)
cb.set_label('hPa / Decade',fontsize=10)

anchored_text = AnchoredText("b", loc=2)
ax2.add_artist(anchored_text)


### Precip Plot ###

ax3 = fig.add_subplot(133, projection = projection)
test3 = plt.contourf(precip.lon,precip.lat,precip[:,:].values,transform=ccrs.PlateCarree(),levels=precip_levs,cmap='BrBG', extend='both')

precip_pval.plot.contourf(axes=ax3,transform=ccrs.PlateCarree(),color='none',edgecolor='black',hatches="..",alpha=0.,add_colorbar = False)
ax3.set_extent([ext_e, ext_w, ext_s, ext_n])
states_provinces = cfeature.NaturalEarthFeature(
    category='cultural',
    name='admin_1_states_provinces_lines',
    scale='50m',
    facecolor='none')
ax3.add_feature(states_provinces, edgecolor='lightgray')
ax3.add_feature(cfeature.COASTLINE)
ax3.add_feature(cfeature.BORDERS)
shape_feature = ShapelyFeature(Reader('/Users/gbromley/Dropbox/Montana_Climate_Project/Study_Area/NGP_Study_Area/Study_Area_08_01_17.shp').geometries(),crs=ccrs.PlateCarree(), facecolor='none',edgecolor='black')
ax3.add_feature(shape_feature)

ax3.title.set_visible(False)
cb = plt.colorbar(test3, cmap='BrBG',fraction=0.037)
cb.set_label('mm / Decade',fontsize=10)
anchored_text = AnchoredText("c", loc=2)
ax3.add_artist(anchored_text)

# *must* call draw in order to get the axis boundary used to add ticks:
fig.canvas.draw()

# Define gridline locations and draw the lines using cartopy's built-in gridliner:
xticks = [-120,-110, -100, -90]
yticks = [30, 40, 50, 60]
ax3.gridlines(xlocs=xticks, ylocs=yticks, color='black', linewidth = 0.1)

# Label the end-points of the gridlines using the custom tick makers:
ax3.xaxis.set_major_formatter(LONGITUDE_FORMATTER) 
ax3.yaxis.set_major_formatter(LATITUDE_FORMATTER)
pf.lambert_xticks(ax3, xticks)
pf.lambert_yticks(ax3, yticks)



plt.tight_layout()

plt.show()

The figure in question

0 个答案:

没有答案