0

The issue

I have a plot of correlation of two variables with most of the values close to either -1 or 1. I'm using a seismic colormap (red & blue w/ white in the middle), but most of the plot is either dark blue (close to -1) or dark red (close to 1), showing little detail near min & max values.

The code

Here's the code block I used for plotting.

#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)

And here's the plot it generates.

enter image description here

The Question

I'd like to adjust the color fill scheme so the middle portion of the colormap, say the -0.9 to 0.9 range, is compacted (almost like a break but not quite) and the color fill better defines the values at the ends. How can I do that? Like a symmetric logarithmic distribution, but biased towards the max & min instead of the middle value.

1 Answer 1

1

There is a keyword argument norm that you can use with pcolormesh in order to change the scale of the color mapping. Take a look at the matplotlib documentation for this. And then you can use the parameter linthresh to change the middle range. I haven't tried it but I think it might solve your problem.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, it works! I had to use not just linthresh, but also linscale in order to compact the middle values. Otherwise, linthresh without linscale will compact the values towards the max & min instead. I'll have to play with the numbers a little, but the effect is what I was looking for. Thanks!
I'm glad it helped :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.