python - matplotlib: How can you specify colour levels in a 2D historgram -


i plot 2d histogram includes both positive , negative numbers. have following code uses pcolormesh unable specify color levels force white color corresponds 0 (i.e., want colorbar symmetric around zero). i've tried imshow.

i know can specify colour levels in plt.contour , plt.contourf can't find way plot 2d histogram using blocks.

any advice appreciated.

import numpy np import matplotlib.pyplot plt matplotlib import cm cm  fig = plt.figure()  # create example histogram asymmetrical around 0 x = np.random.rand(400) y = np.random.rand(400)     z, xedges, yedges = np.histogram2d(x, y, bins=10)    z = z - 2.  plt.pcolormesh(xedges, yedges, z, cmap=cm.rdbu_r)  plt.colorbar() plt.savefig('test.png') 

enter image description here

add vmin , vmax parameters equal absolute values

plt.pcolormesh(xedges, yedges, z, cmap=cm.rdbu_r, vmin=-7, vmax=7) 

and see if result

enter image description here


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -