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

1

1 Answer 1

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

1
  • Thanks! exactly what I needed
    – OMRY VOLK
    Jan 17, 2016 at 12:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.