Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black and white colorbar

I usually use the "seismic" colorbar of matplotlib.

For a publication need, I have to use black and white colors. I would like to keep the same aspect as "seismic" (i.e., blackest values for highest min and max values), as shown on the picture:

enter image description here

How do I make this conversion?

like image 989
user5276228 Avatar asked Dec 25 '22 12:12

user5276228


1 Answers

In my view, the best idea is to use a grey ramp instead of a diverging colourbar:

import numpy as np
import matplotlib.pyplot as plt

data = 2 * np.random.random((100, 100)) - 1

plt.imshow(data, cmap='Greys', interpolation='none')

Example of greyscale colourbar

You can use gray as well, but it's just a reversed version and will give you white for positive values, which is not conventional for seismic data.

If you're set on doing what you ask, I think the easiest way might be to use PIL to convert images to greyscale.

plt.imshow(data, cmap='jet', interpolation='none')
plt.savefig('image.png')

Now convert it and save:

from PIL import Image
im = Image.open('image.png')
im = im.convert('L')
im.save('image_grey.png')
like image 55
Matt Hall Avatar answered Jan 11 '23 04:01

Matt Hall