3

I have a pcolormesh plot wherein the color map is clipped by setting vmin and and vmax to strictly within the range of the values plotted. Is there a way to have the associated colorbar detatch a chunk from the bottom and from the top to signify that the relevant colors are outside the range of the color map?

implmentor
  • 1,336
  • 4
  • 20
  • 31
gspr
  • 10,861
  • 3
  • 41
  • 72

1 Answers1

4

Yes, you need to use the extend = both keyword for the colorbar, and then set the over and under colors for the colormap of the pcolormesh object

import matplotlib.pyplot as plt
import numpy as np

data=np.random.rand(10,10)

fig=plt.figure()
ax=fig.add_subplot(111)

p=ax.pcolormesh(data,vmin=0.2,vmax=0.8,cmap='gray')

p.cmap.set_over('red')
p.cmap.set_under('blue')

fig.colorbar(p,extend='both')

plt.show()

enter image description here

tmdavison
  • 58,077
  • 12
  • 161
  • 147