2

I have a 2D data set with values between 0.5 and 2. I want to show it with imshow and seismic color map but I need the value 1 to match the white color.

import numpy as np
import matplotlib.pyplot as plt
data = np.random.random((100,100))*2
data[data<0.5]=0.5
plt.imshow(data,cmap='seismic')
plt.colorbar()

example

I did:

plt.imshow(data,cmap='seismic',vmin=0,vmax=2)

enter image description here

But I can't have the 0-0.5 values in my colorbar.

Thanks

OMRY VOLK
  • 1,429
  • 11
  • 24
  • Possible duplicate: http://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib – ktbiz Jan 17 '16 at 09:12

1 Answers1

2

use ColorBar.set_clim():

import numpy as np
import matplotlib.pyplot as plt
data = np.random.random((100,100))*2
data[data<0.5]=0.5
plt.imshow(data,cmap='seismic', vmin=0.5, vmax=2)
c = plt.colorbar()
c.set_clim(0, 2)

the output:

enter image description here

HYRY
  • 94,853
  • 25
  • 187
  • 187