BoundaryNormを散布図のノーマライザーとして使用すると、非常に簡単にカスタムの個別カラーバーを作成できます。奇妙なビット(私の方法で)灰色として0ショーをしています。
私はしばしばcmap.set_bad()を使い、データをマスクされた配列に変換します。それは0グレーを作る方がはるかに簡単ですが、私はこれを散布機またはカスタムcmapで動作させることができませんでした。
別の方法として、独自のcmapを作成したり、既存のものを読み込んで、特定のエントリだけを上書きすることができます。
# setup the plot
fig, ax = plt.subplots(1,1, figsize=(6,6))
# define the data
x = np.random.rand(20)
y = np.random.rand(20)
tag = np.random.randint(0,20,20)
tag[10:12] = 0 # make sure there are some 0 values to showup as grey
# define the colormap
cmap = plt.cm.jet
# extract all colors from the .jet map
cmaplist = [cmap(i) for i in range(cmap.N)]
# force the first color entry to be grey
cmaplist[0] = (.5,.5,.5,1.0)
# create the new map
cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
# define the bins and normalize
bounds = np.linspace(0,20,21)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
# make the scatter
scat = ax.scatter(x,y,c=tag,s=np.random.randint(100,500,20),cmap=cmap, norm=norm)
# create a second axes for the colorbar
ax2 = fig.add_axes([0.95, 0.1, 0.03, 0.8])
cb = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm, spacing='proportional', ticks=bounds, boundaries=bounds, format='%1i')
ax.set_title('Well defined discrete colors')
ax2.set_ylabel('Very custom cbar [-]', size=12)
私は個人的に特定の値を読み、そのビットハード20色の異なると思いますが、もちろんあなたに最高のthats。
は、[この](http://matplotlib.org/examples/api/colorbar_only.html)または[この]ありません(http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations)ヘルプ? –
リンクのおかげさしですが、2番目の例は、(一見)些細な作業を実行するためには非常に複雑すぎるということです - 最初のリンクは便利です – bph