左侧箭头
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure(figsize=(4,3))
ax = fig.add_axes([0.05,0.5,0.8,0.1])
cmap = mpl.colors.ListedColormap(['r','g','b','c'])
cmap.set_over('0.25')
cmap.set_under('0.75')
bounds = [1,2,3,4,5]
norm = mpl.colors.BoundaryNorm(bounds,cmap.N)
cb = mpl.colorbar.ColorbarBase(ax,
cmap = cmap,
norm = norm,
boundaries = [0]+bounds,
orientation = 'horizontal',
extend = 'min')
效果图:

右侧箭头
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure(figsize=(4,3))
ax = fig.add_axes([0.05,0.5,0.8,0.1])
cmap = mpl.colors.ListedColormap(['r','g','b','c'])
cmap.set_over('0.25')
cmap.set_under('0.75')
bounds = [1,2,3,4,5]
norm = mpl.colors.BoundaryNorm(bounds,cmap.N)
cb = mpl.colorbar.ColorbarBase(ax,
cmap = cmap,
norm = norm,
boundaries = bounds+[6],
orientation = 'horizontal',
extend = 'max')
效果图:

两端箭头
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure(figsize=(4,3))
ax = fig.add_axes([0.05,0.5,0.8,0.1])
cmap = mpl.colors.ListedColormap(['r','g','b','c'])
cmap.set_over('0.25')
cmap.set_under('0.75')
bounds = [1,2,3,4,5]
norm = mpl.colors.BoundaryNorm(bounds,cmap.N)
cb = mpl.colorbar.ColorbarBase(ax,
cmap = cmap,
norm = norm,
boundaries = bounds+[6],
orientation = 'horizontal',
extend = 'both')
效果图:
