Широкоугольные этикетки с проекцией LCC - PullRequest
0 голосов
/ 13 июня 2019

Мне нужно добавить метки широты / долготы к моей проекции LCC. Удивительно, насколько сложным это оказалось. Я использовал код здесь , и он работал очень хорошо для одной фигуры на панели. Все мои цифры, к сожалению, должны быть 3-4 панелями. 2 проблемы.

  1. Привязанный текст (предполагается, что это «а») на участке 1 исчезает.

  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

...