- 积分
- 203
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-8-30
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我想绘制不等间距的填色图,但是不知道怎么设置,求大佬们看看!!
from matplotlib.colors import ListedColormap
import matplotlib.colors as mcolors
rgb=(
[ 255,255,255],
[ 203,205,252],
[ 91,90,254],
[ 8,97,163],
[ 15,173,61],
[ 160,226,13],
[ 219,244,2],
[ 254,213,0],
[ 255,133,5],
[ 253,94,3]
)
rgb=np.array(rgb)/255.0
new_cmap=ListedColormap(rgb,name='new_cmap')
bcfile=xr.open_dataset("F:/degar_HTAPv3_2013/edgar_HTAPv3_2013_BC/edgar_HTAPv3_2013_BC.nc")
#print(bcfile)
x=['HTAPv3_1_International_Shipping','HTAPv3_2_1_Domestic_Aviation','HTAPv3_2_2_International_Aviation','HTAPv3_3_Energy',\
'HTAPv3_4_1_Industry','HTAPv3_4_2_Fugitive','HTAPv3_4_3_Solvents','HTAPv3_5_1_Road_Transport','HTAPv3_5_2_Brake_and_Tyre_wear',\
'HTAPv3_5_3_Domestic_shipping','HTAPv3_5_4_Other_ground_transport','HTAPv3_6_Residential','HTAPv3_7_Waste',\
'HTAPv3_8_1_Agricultural_waste_burning','HTAPv3_8_2_Agriculture_livestock','HTAPv3_8_3_Agriculture_crops']
title=['International_Shipping','Domestic_Aviation','International_Aviation','Energy',\
'Industry','Fugitive','Solvents','Road_Transport','Brake_and_Tyre_wear',\
'Domestic_shipping','Other_ground_transport','Residential','Waste',\
'Agricultural_waste_burning','Agriculture_livestock','Agriculture_crops']
lat=bcfile['lat']
lon=bcfile['lon']
fig=plt.figure(figsize=(10,9))
norm = mcolors.Normalize(vmin=0, vmax=9)
for i in range(16):
data=bcfile[x[i]].loc['2013-07-15',:,:]
axe=plt.subplot(4,4,i+1,projection=ccrs.PlateCarree())
clevs_500_t = np.array([0,0.005,0.05,0.1,0.5,1,1.5,2,3,5,9])
cf = axe.contourf(lon, lat, data, clevs_500_t, cmap=new_cmap,norm=norm,transform=ccrs.PlateCarree(),
zorder=0)
axe.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.5,color='k')
axe.set_extent([105,135, 22, 45], crs=ccrs.PlateCarree())
axe.set_xticks(np.arange(110, 135+5, 10), crs=ccrs.PlateCarree())
axe.set_yticks(np.arange(27, 47, 10), crs=ccrs.PlateCarree())
axe.xaxis.set_major_formatter(LongitudeFormatter())
axe.yaxis.set_major_formatter(LatitudeFormatter())
axe.tick_params(labelcolor='k',length=5)
labels = axe.get_xticklabels() + axe.get_yticklabels()
[label.set_fontproperties(FontProperties(fname="C:/WINDOWS/Fonts/times.ttf",size=8)) for label in labels]
axe.set_title(title[i],loc='center',fontproperties=SimSun,fontsize=10,pad=2.5)
if i!=0 and i!=4 and i!= 8 and i!=12:
axe.set_yticklabels("")
if i<12:
axe.set_xticklabels("")
fig.subplots_adjust(bottom=0.23)
rect = [0.2, 0.14, 0.6, 0.015]
cbar_ax=fig.add_axes(rect)
cb = fig.colorbar(cf, cax=cbar_ax,shrink=0.6,orientation='horizontal',spacing='uniform')
cb.set_label('单位: $\mathrm{(ton/month)}$', fontproperties=SimSun, fontsize=10)
cb.ax.tick_params(length=0)
plt.show()
bcfile.close()
出图如下
结果颜色是按照等间距填进去的,怎么解决啊
|
-
|