python plot 渐变颜色不显示_为什么matplotlib颜色条不显示任何刻度标记和标签

我一直试图根据某些数据绘制带有颜色的形状文件多边形并添加一个颜色条。下面显示的是我为此编写的代码。它正确地给出了绘图,但没有标签或刻度线的颜色栏。为什么matplotlib颜色条不显示任何刻度标记和标签

fig, ax = plt.subplots(1,1,figsize=(12,10), subplot_kw={'projection': ccrs.PlateCarree()})

ptchs1 = []

for nshp in indx[0,:]:

ptchs = []

pts = np.array(shapes[nshp].points)

pts =pts[np.unique(np.where(~np.isnan(pts[:,:]))[0]),:]

prt = shapes[nshp].parts

par = list(prt) + [pts.shape[0]]

for pij in xrange(len(prt)):

ptchs.append(Polygon(pts[par[pij]:par[pij+1]]))

ptchs1.append(Polygon(pts[par[pij]:par[pij+1]]))

ind=np.where(indx==nshp)[1] ;

ax.add_collection(PatchCollection(ptchs,facecolor=my_cmap[np.where(indx==nshp)[1],:],edgecolor='k', linewidths=.5),ccrs.PlateCarree())

plt.text(xtext[ind], ytext[ind],dnme[ind][0:7],fontsize=8,color='k',fontweight='bold', ha='center',va='center',transform=ccrs.Geodetic())

ax.set_xlim(np.round(mnbbx[0]).astype(int)-0.5,np.round(mxbbx[2]).astype(int)+0.5,2)

ax.set_ylim(np.round(mnbbx[1]).astype(int)-0.5,np.round(mxbbx[3]).astype(int)+0.5,2)

m = cm.ScalarMappable(cmap=cmap)

m.set_array([])

m.set_clim(-0.5, 14+0.5)

divider = make_axes_locatable(ax)

cax = divider.append_axes("right",aspect=20,size="5%",pad=0.05,map_projection=ccrs.PlateCarree())

cb=fig.colorbar(m,cax=cax,norm=norm)

cb.set_ticks(np.arange(0,14))

cb.set_label('RainFall(mm/day)', rotation=90)

cb.set_ticklabels([1,5,10,20,30,40,70,100,130,160,190,220,250])

xticks = np.arange(np.round(mnbbx[0]).astype(int)-0.5,np.round(mxbbx[2]).astype(int)+0.5,2)

yticks = np.arange(np.round(mnbbx[1]).astype(int)-0.5,np.round(mxbbx[3]).astype(int)+0.5,2)

gl = ax.gridlines(crs=ccrs.PlateCarree(),draw_labels=True,linewidth=0.7, color='black', alpha=1)

gl.xlabels_bottom = False ; gl.ylabels_right = False

degree_locator = mticker.MaxNLocator(nbins=4) #it will give gridlines of 4*4 size

gl.xlocator = degree_locator

gl.ylocator = degree_locator

_DEGREE_SYMBOL = u'\u00B0'

gl.xformatter = LONGITUDE_FORMATTER #it will change lon to degree format

gl.yformatter = LATITUDE_FORMATTER

gl.ylabel_style = {'size': 12, 'color': 'black'} # here we can adjust color and size of ticks

gl.xlabel_style = {'color': 'black', 'size': 12 }

plt.show()

任何人都可以帮助我,为什么没有生成彩条刻度线和标签?

我已经更新了我的彩条与这段代码绘制,它正确地绘制,但主要情节和彩条大小是不同的(无论是大或小)

col_bnd=[0,1, 5, 10, 20, 30, 40, 70, 100, 130, 160, 190, 220, 250,300]

norm = colors.BoundaryNorm(col_bnd, cmap.N)

col_bnd=[1, 5, 10, 20, 30, 40, 70, 100, 130, 160, 190, 220, 250]

ax1, ax2 = mpl.colorbar.make_axes(ax, shrink=0.68,aspect=20,pad=0.05)

cbar = mpl.colorbar.ColorbarBase(ax1, cmap=cmap,norm=norm,ticks=col_bnd,boundaries=None,format='%1i') #mpl.colors.Normalize(vmin=-0.5, vmax=1.5))

cbar.set_clim(0, 300)

cbar.set_label('RainFall(mm/day)', rotation=90)

谁能告诉,如何使主要阴谋和彩条相同的大小?

2015-06-16

pkv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值