From: mdekauwe <mdekauwe@gm...>  20100913 15:49:13

Hi, I am setting a colourbar where I explictly set the tick intervals. However I would like to exclude the colour black from this colourbar. The reason for this is I would like to overplot some contour lines in black, so would like to make them stand out. An example...where I would like to exclude black as the bottom colour of the colourbar, i.e. use the next level of gray. import numpy as np from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib as mpl data = np.random.randint(0,50,100*100).reshape(100, 100) m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5, resolution='c', projection='cyl') fig = plt.figure(figsize=(8, 6)) ax = fig.add_axes([0.1, 0.1, 0.6, 0.7]) m.ax = ax colourmap = plt.cm.Greys_r ticks = [0, 10, 20, 30, 40, 50] norm = colors.BoundaryNorm(ticks, colourmap.N) im = m.imshow(data, colourmap, norm=norm, interpolation='nearest') pos = ax.get_position() l, b, w, h = pos.bounds cax = plt.axes([l+w+0.045, b, 0.05, h]) cbar = mpl.colorbar.ColorbarBase(cax, cmap=colourmap, norm=norm, ticks=ticks) plt.show() Many thanks, Martin  View this message in context: http://old.nabble.com/Excludecolourfromacolourbartp29699746p29699746.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20100913 20:10:57

So far I have tried this... colourmap = cm.get_cmap("Greys_r") colourmap = colourmap._segmentdata # exclude 0, 0, 0...i.e. black from dictionary bvals = colourmap['blue'][1:] gvals = colourmap['green'][1:] rvals = colourmap['red'][1:] colourmap = { "blue":bvals, "green":gvals, "red":rvals } colourmap = cm.set_cmap(colourmap) But it doesn't seem to like the set_cmap command colourmap = cm.set_cmap(colourmap) AttributeError: 'module' object has no attribute 'set_cmap' So I guess that isn't the way, nor I suspect is that all that elegant. Martin mdekauwe wrote: > > Hi, > > I am setting a colourbar where I explictly set the tick intervals. However > I would like to exclude the colour black from this colourbar. The reason > for this is I would like to overplot some contour lines in black, so would > like to make them stand out. > > An example...where I would like to exclude black as the bottom colour of > the colourbar, i.e. use the next level of gray. > > import numpy as np > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > import matplotlib.colors as colors > import matplotlib as mpl > > data = np.random.randint(0,50,100*100).reshape(100, 100) > m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5, > resolution='c', projection='cyl') > fig = plt.figure(figsize=(8, 6)) > ax = fig.add_axes([0.1, 0.1, 0.6, 0.7]) > m.ax = ax > > colourmap = plt.cm.Greys_r > ticks = [0, 10, 20, 30, 40, 50] > norm = colors.BoundaryNorm(ticks, colourmap.N) > im = m.imshow(data, colourmap, norm=norm, interpolation='nearest') > pos = ax.get_position() > l, b, w, h = pos.bounds > cax = plt.axes([l+w+0.045, b, 0.05, h]) > cbar = mpl.colorbar.ColorbarBase(cax, cmap=colourmap, norm=norm, > ticks=ticks) > plt.show() > > Many thanks, > > Martin >  View this message in context: http://old.nabble.com/Excludecolourfromacolourbartp29699746p29702394.html Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: mdekauwe <mdekauwe@gm...>  20100913 22:31:23

The solution incase anyone has a similar issue... data = np.random.randint(0,50,100*100).reshape(100, 100) m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5, resolution='c', projection='cyl') fig = plt.figure(figsize=(8, 6)) ax = fig.add_axes([0.1, 0.1, 0.6, 0.7]) m.ax = ax ticks = [0, 10, 20, 30, 40, 50] colours = cm.Greys_r(np.linspace(0.3, 1.0, 6)) colourmap = colors.ListedColormap(colours) norm = colors.BoundaryNorm(ticks, colourmap.N) im = m.imshow(data, cmap=colourmap, norm=norm, interpolation='nearest') pos = ax.get_position() l, b, w, h = pos.bounds cax = plt.axes([l+w+0.045, b, 0.05, h]) cbar = mpl.colorbar.ColorbarBase(cax, cmap=colourmap, norm=norm, ticks=ticks) plt.show()  View this message in context: http://old.nabble.com/Excludecolourfromacolourbartp29699746p29703615.html Sent from the matplotlib  users mailing list archive at Nabble.com. 