I want to plot some data with a logarithmic color code where a decade limit is indicated by a white/black interface. Grey levels are used to show some subdivisions of a decade. My problem is that there are two white neighboring regions in each decade even though the color map has the right number of entries (at least I think). Could someone help please?
In the meantime I made some tests and I found that it's the second color of the repeating pattern that is not used (the gray(0.25)), but I still have no idea why.
Here is the short version of the code:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors
# generate data
x = y = np.linspace(-3, 3, 200)
im = 1800*np.exp(-(np.outer(x,x) + y**2))
im = im / im.max() # normalize
# set logarithic levels (with small steps)
levS = np.array([1e-3,2e-3,4e-3,6e-3,8e-3,
1e-2,2e-2,4e-2,6e-2,8e-2,
0.1,0.2,0.4,0.6,0.8,
1])
# (5 intervals in one decade )
# avoid white patches by filling up to lowest level
im[ im < levS.min() ] = levS.min()
# make a list of 5 colors to create a colormap from
mapColS = [plt.cm.gray(0),plt.cm.gray(0.25),plt.cm.gray(0.50),
plt.cm.gray(0.7),plt.cm.gray(0.99)]
# repeat 3 times for the three decades
mapColS = mapColS + mapColS + mapColS
MyCmap=colors.ListedColormap(mapColS) # make color map
fig13g = plt.figure(1000) #create figure
ax13g = fig13g.add_subplot(111)
# plot lines
cax = plt.contour(im, levS, linewidths = 0.5,
norm=colors.LogNorm(), colors = 'k')
# fill with colors
cax = plt.contourf(im, levS, norm=colors.LogNorm(),
cmap=MyCmap) # plt.cm.jet OR MyCmap
# show log color bar
cbar = fig13g.colorbar(cax, orientation='vertical',
spacing='regular',ticks= levS)
Here are the results:
For comparisson, using 'jet' there is no problem: