How to view all colormaps available in matplotlib?

前端 未结 2 779
自闭症患者
自闭症患者 2020-12-09 20:13

I was wondering if there is a function call that can give me the name of all colormaps available in matplotlib?

It used to be possible by something along the lines o

2条回答
  •  半阙折子戏
    2020-12-09 20:32

    Here's some code that plots all available colormaps linked to their ID's

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    def plot_colorMaps(cmap):
    
        fig, ax = plt.subplots(figsize=(4,0.4))
        col_map = plt.get_cmap(cmap)
        mpl.colorbar.ColorbarBase(ax, cmap=col_map, orientation = 'horizontal')
    
        plt.show()
    
    for cmap_id in plt.colormaps():
        print(cmap_id)
        plot_colorMaps(cmap_id)
    

    The output looks like this

    Accent

    Accent_r

    Blues

    etc...

提交回复
热议问题