【问题标题】:Customize existing color bar自定义现有颜色条
【发布时间】:2020-11-02 17:46:29
【问题描述】:

如何将发散色条的白色部分移向最大值或最小值。

import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib as mpl
norm = mpl.colors.Normalize(vmin=0,vmax=600)
fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)
cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cm.PiYG,
                                norm=norm,
                                orientation='horizontal')
cb1.set_label('Some Units')
fig.show()

【问题讨论】:

    标签: python matplotlib colors colorbar


    【解决方案1】:

    你必须使用TwoSlopeNorm规范化类

    In [5]: import matplotlib.pyplot as plt 
       ...: import matplotlib as mpl 
       ...:  
       ...: norm = mpl.colors.TwoSlopeNorm(vcenter=450, vmin=0, vmax=600) 
       ...: fig, ax = plt.subplots(figsize=(6, 1)) 
       ...: fig.subplots_adjust(bottom=0.5) 
       ...: cb1 = mpl.colorbar.ColorbarBase(ax, cmap=mpl.cm.PiYG, 
       ...:                                 norm=norm, 
       ...:                                 orientation='horizontal') 
       ...: cb1.set_label('Some Units')    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 2012-03-08
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      相关资源
      最近更新 更多