Reverse colormap in matplotlib

前端 未结 7 789
小蘑菇
小蘑菇 2020-11-28 02:04

I would like to know how to simply reverse the color order of a given colormap in order to use it with plot_surface.

7条回答
  •  遥遥无期
    2020-11-28 02:47

    In matplotlib a color map isn't a list, but it contains the list of its colors as colormap.colors. And the module matplotlib.colors provides a function ListedColormap() to generate a color map from a list. So you can reverse any color map by doing

    colormap_r = ListedColormap(colormap.colors[::-1])
    

提交回复
热议问题