要设置颜色条上的刻度,可以使用cb.set_ticks(bins**(1/3.))。也可以直接缩放颜色贴图(clr_map((i/400.)**(1./3)))。在import matplotlib.pyplot as plt
import matplotlib.colors
import matplotlib.colorbar
import numpy as np
def draw_legend (clr_map):
""" Draw a color bar legend
with a qubic root colormap
"""
# Version 1, scale boundaries, set ticks to colorbar values
fig = plt.figure(figsize=(6,4))
ax_legend = fig.add_axes([0.26, 0.7, 0.48, 0.1], zorder=3)
ax_legend.set_title("Version 1\nscale boundaries, set ticks to colorbar values")
grads = np.linspace(0.,1.,400)
bins = np.linspace(0.,1.,11)
scheme = [clr_map(i/400.) for i in range(400)]
cmap = matplotlib.colors.ListedColormap(scheme)
cb = matplotlib.colorbar.ColorbarBase(ax_legend, cmap=cmap, ticks=bins, boundari