您可以使用matplotlib.colors.LinearSegmentedColormap() 或matplotlib.colors.ListedColormap() 定义自己的颜色图并将其用于您的绘图。
例子:
import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
import matplotlib.colors
x = np.arange(0,25)
a = np.random.randint(0,130, size=(25,25))-115
a = np.sort(a).reshape(25,25)
colors = ["#eaa941", "#efef39", "#53a447", "#3b387f", "#48a2ba"]
cmap= matplotlib.colors.ListedColormap(colors)
cmap.set_under("crimson")
cmap.set_over("w")
norm= matplotlib.colors.Normalize(vmin=-100,vmax=-0)
fig, ax = plt.subplots()
im = ax.contourf(x,x,a, levels=[-100,-80,-60,-40,-20,0],
extend='both',cmap=cmap, norm=norm)
fig.colorbar(im, extend="both")
plt.show()