colorbar

作者: 榴莲气象 | 来源:发表于2018-11-29 21:36 被阅读0次

    Customizing Colorbars in Python Data Science Handbook


    plt.colorbar

    长宽尺度

    调整colorbar的长度

    shrink=legend.shrink
    shrink=0.5 缩小一倍
    shrink=0.92 并使其长度为原来的92%

    【long】lxyflashlxy@qq.com 2018/11/29 21:05:45

    是我自定义的类啦
    你自己 定义自己的数值
    还有一些办法 可以自如的控制 legend的 长和宽
    这里就不细说了
    【int】LL(905102548) 2018/11/29 21:13:05
    好的,谢谢指教,我再去看看
    【int】nick carter(464539880) 21:23:57
    @LL 右侧是尖的如何设置的

    _r 色标颠倒


    渐变色位置,开头结尾

    渐变色调整

    > norm = MidpointNormalize(vmin=ccn_min, vmax=ccn_max, midpoint=14)
    > m.scatter(lon, lat, latlon=True,
    >           c=ccn, s=tcb,
    >           cmap=CM.get_cmap('RdBu_r',200),  norm=norm, alpha=0.5)
    

    可以有多种选择,这里我最终选择的是spectral,那个1000是热度标尺被分隔成多少块,数字越多,颜色区分越细致


    This example shows how to build colorbars without an attached mappable

    image

    Python matplotlib change default color for values exceeding colorbar range
    Colormap.set_under(cmap,color='k')


    Set Colorbar Range in matplotlib

    plt.clim(-4,4)

    import matplotlib as mpl...ax, _ = mpl.colorbar.make_axes(plt.gca(), shrink=0.5)cbar = mpl.colorbar.ColorbarBase(ax, cmap=cm, norm=mpl.colors.Normalize(vmin=-0.5, vmax=1.5))cbar.set_clim(-2.0, 2.0)


    刻度

    matplotlib colorbar tick label formatting
    cbar_num_format = "%d"
    pl.colorbar(myplot, format='%.0e')
    cbar.ax.set_yticklabels(np.arange(cbar_min, cbar_max+cbar_step, cbar_step), fontsize=16, weight='bold')
    Scientific notation colorbar in matplotlib

    > import matplotlib.pyplot as plt 
    > import numpy as np
    > import matplotlib.ticker as ticker
    > img = np.random.randn(300,300)
    > myplot = plt.imshow(img)
    > def fmt(x, pos):   
    >  a, b = '{:.2e}'.format(x).split('e')  
    >  b = int(b)
    >   return r'${} \times 10^{{{}}}$'.format(a, b)
    > plt.colorbar(myplot, format=ticker.FuncFormatter(fmt))
    > plt.show()
    shrink=0.92  并使其长度为原来的92%
    
    image

    相关文章

      网友评论

        本文标题:colorbar

        本文链接:https://www.haomeiwen.com/subject/wgsqcqtx.html