我一直在使用from_levels_and_colors函数,因此我可以在pcolormesh图上使用扩展颜色条,类似于contourf.这是我的示例contourf plot:
import numpy as np
import matplotlib.pyplot as plt
a = np.arange(12)[:,np.newaxis] * np.ones(8)
levels = np.arange(1.5, 10, 2)
plt.contourf(a, cmap='RdYlBu', levels=levels, extend='both')
plt.colorbar()
为了产生类似的pcolormesh图,我需要提供一系列颜色,所以我有:
from matplotlib.colors import from_levels_and_colors
n_colors = len(levels) + 1
cmap = plt.get_cmap('RdYlBu', n_colors)
colors = cmap(range(cmap.N))
cmap, norm = from_levels_and_colors(levels, colors, extend='both')
plt.pcolormesh(a, cmap=cmap, norm=norm)
plt.colorbar()
pcolormesh中的中间四种颜色比contourf中的颜色浅.我如何选择它们