官术网_书友最值得收藏!

Choosing matplotlib color maps

The matplotlib color maps are getting a lot of criticism lately because they can be misleading; however, most colormaps are just fine in my opinion. The defaults are getting a makeover in matplotlib 2.0 as announced at http://matplotlib.org/style_changes.html (retrieved July 2015). Of course, there are some good arguments that do not support using certain matplotlib colormaps, such as jet. In art, as in data analysis, almost nothing is absolutely true, so I leave it up to you to decide. In practical terms, I think it is important to consider how to deal with print publications and the various types of color blindness. In this recipe, I visualize relatively safe colormaps with colorbars. This is a tiny selection of the many colormaps in matplotlib.

How to do it...

  1. The imports are as follows:
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    from dautil import plotting
  2. Plot the datasets with the following code:
    fig, axes = plt.subplots(4, 4)
    cmaps = ['autumn', 'spring', 'summer', 'winter',
             'Reds', 'Blues', 'Greens', 'Purples',
             'Oranges', 'pink', 'Greys', 'gray',
             'binary', 'bone', 'hot', 'cool']
    
    for ax, cm in zip(axes.ravel(), cmaps):
        cmap = plt.cm.get_cmap(cm)
        cb = mpl.colorbar.ColorbarBase(ax, cmap=cmap, 
                                       orientation='horizontal')
        cb.set_label(cm)
        ax.xaxis.set_ticklabels([])
    
    plt.tight_layout()
    plt.show()

Refer to the following plot for the end result:

The notebook is in the choosing_colormaps.ipynb file in this book's code bundle. The color maps are used in various visualizations in this book.

See also

主站蜘蛛池模板: 当涂县| 东乌珠穆沁旗| 文昌市| 勃利县| 会昌县| 达孜县| 比如县| 灌阳县| 泸州市| 峡江县| 德令哈市| 牟定县| 垫江县| 庆云县| 北京市| 梓潼县| 邢台市| 石门县| 长治县| 湘阴县| 唐海县| 苏尼特右旗| 潮安县| 娄底市| 梁平县| 广饶县| 宁阳县| 常州市| 连云港市| 呼伦贝尔市| 建平县| 西和县| 泸州市| 门头沟区| 桐柏县| 丰宁| 宜昌市| 洪泽县| 南华县| 永登县| 吉安市|