【问题标题】:Using matplotlib to draw color bar with distinguishable and uncontinues colors使用 matplotlib 绘制具有可区分和不连续颜色的颜色条
【发布时间】:2012-02-26 08:11:43
【问题描述】:

下图中的彩条是用matlab绘制的。我想知道是否可以在 python/matplotlib 中绘制类似的颜色条?我需要颜色条中的 un-smoothing 颜色变化,以便值 0-5 以非常可区分和不连续颜色表示。如果可能的话,你能给我举个例子吗?谢谢~

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    使用ListedColormapBoundaryNorm

    import numpy as np
    import matplotlib as mpl
    from matplotlib import pyplot
    data = np.floor(np.random.random((10,10)) * 6)
    cmap = mpl.colors.ListedColormap(['w', 'b', 'g', 'y', '#ff8c00', 'r'])
    norm = mpl.colors.BoundaryNorm([0,1,2,3,4,5,6], cmap.N)
    pyplot.imshow(data, cmap=cmap, norm=norm, interpolation='none')
    pyplot.colorbar()
    pyplot.show()
    

    使用 ListedColormap 的一些示例:colorbarsmulticolored lines

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-10
      • 2018-10-06
      • 2021-02-08
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-27
      相关资源
      最近更新 更多