I\'m trying to plot log ratios from the range -3 to 3 and want negative ratios to be green and positive to be red, with a log ratio of 0 (center) to be white in color. None
How about the following that uses LinearSegmentedColormap:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
cmapGR = LinearSegmentedColormap(
'GreenRed',
{
'red': ((0.0, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0)),
'green':((0.0, 1.0, 1.0),
(0.5, 1.0, 1.0),
( 1.0, 0.0, 0.0)),
'blue': ((0.0, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 0.0, 0.0))
},)
plt.imshow(np.array([np.arange(200) for i in range(200)]), cmap=cmapGR)
plt.show()
It produces the following
See e.g. http://matplotlib.org/examples/pylab_examples/custom_cmap.html for more uses and other examples.