【发布时间】:2017-01-20 08:53:00
【问题描述】:
问题
我有两个变量的相关图,其中大部分值接近 -1 或 1。我使用的是地震颜色图(红色和蓝色,中间是白色),但大部分图是深蓝色(接近 -1)或深红色(接近 1),在最小值和最大值附近显示很少的细节。
代码
这是我用于绘图的代码块。
#Set variables
lonlabels = ['0','45E','90E','135E','180','135W','90W','45W','0']
latlabels = ['90S','60S','30S','Eq.','30N','60N','90N']
bounds = np.array([-1.0,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1.0])
#Create basemap
fig,ax = plt.subplots(figsize=(15.,10.))
m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,llcrnrlon=0,urcrnrlon=360.,lon_0=180.,resolution='c')
m.drawcoastlines(linewidth=1,color='w')
m.drawcountries(linewidth=1,color='w')
m.drawparallels(np.arange(-90,90,30.),linewidth=0.3)
m.drawmeridians(np.arange(-180.,180.,45.),linewidth=0.3)
meshlon,meshlat = np.meshgrid(lon,lat)
x,y = m(meshlon,meshlat)
#Plot variable
corre = m.pcolormesh(x,y,corrcoef,cmap='seismic', shading='gouraud',vmin=-1.0,vmax=1.0)
#Set titles & labels
#Colorbar
cbar = m.colorbar(corre,size="8%",ticks=bounds,location='bottom',pad=0.8)
cbar.set_label(label='Correlation Coefficient',size=25)
cbar.set_ticklabels(bounds)
for t in cbar.ax.get_xticklabels():
t.set_fontsize(25)
#Titles
fig.suptitle('Correlation of Local Precipitation to Global (CanESM2)',fontsize=30,x=0.51,y=0.92)
ax.set_xlabel('Longitude',fontsize=25)
ax.set_xticks(np.arange(0, 405,45))
ax.set_xticklabels(lonlabels,fontsize=20)
ax.set_ylabel('Latitude', fontsize=25)
ax.set_yticks(np.arange(-90,120,30))
ax.set_yticklabels(latlabels,fontsize=20)
这是它生成的情节。
问题
我想调整颜色填充方案,以便颜色图的中间部分,例如 -0.9 到 0.9 范围,被压缩(几乎像中断但不完全)并且颜色填充更好地定义了值结束。我怎样才能做到这一点?类似于对称对数分布,但偏向最大值和最小值,而不是中间值。
【问题讨论】:
标签: python matplotlib colors colormap