【问题标题】:Crop extended marker in colorbar在颜色栏中裁剪扩展标记
【发布时间】:2020-06-04 17:11:57
【问题描述】:

在使用contourf 时,我必须使用extend='min' 来为低于我给定范围(负值)的值着色。我想问一下如何裁剪这个扩展标记(箭头所指)

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(5,5))
ax = plt.contourf(x, y, z, cmap='Spectral', vmin=0, vmax=60, norm=norm, extend='min')

# colorbar
cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
cb = fig.colorbar(ax, cax=cax)

把它做成这样的东西

谢谢

【问题讨论】:

    标签: python python-3.x matplotlib colorbar contourf


    【解决方案1】:

    您可以使用以下代码:

    bounds = [5*i for i in range(13)]
    cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
    fig.colorbar(mpl.cm.ScalarMappable(cmap = 'Spectral', norm = norm),
                 cax = cax,
                 ticks = bounds,
                 boundaries = [0] + bounds[1:-1] + [60])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多