如何缩小ColorBar占用的区域?

2024-10-03 09:12:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在一块地里放两块色条,配一张地图。不幸的是,色条和情节本身一样大。即使在色条代码中使用收缩,它也只会收缩色条,而不会收缩它们所占的大小。在

有没有一种简单的方法可以让我的图占用更多的空间,而让色条占用更少的空间?有没有一种简单的方法让色条在底部并排出现?在

Plot with colourbars 代码在下面

plt.clf()
my_cmap = cm.get_cmap('YlOrRd')


cs = map.contourf(x,y,bj,levels = Y,cmap=my_cmap,locator=mpl.ticker.LogLocator())


norm = mpl.colors.BoundaryNorm(bounds, my_cmap.N)
    cb1 = plt.colorbar(cmap=my_cmap, 
                norm=norm,
                boundaries=bounds,
                extend='both',
                orientation="horizontal",
                ticks=bounds,
                shrink = 0.35)
    cb1.set_label('Increase in Black Carbon')
    bj = -bj
    ymap = cm.get_cmap('PuBu')


    cs = map.contourf(x,y,bj,levels = Y,cmap=ymap,locator=mpl.ticker.LogLocator())

    # set colourbar with location and size, with labels.
    norm = mpl.colors.BoundaryNorm(bounds,ymap.N)
    cb2 = plt.colorbar(cmap=my_cmap, 
                norm=norm,
                boundaries=bounds,
                extend='both',
                orientation="horizontal",
                ticks=bounds,
                shrink=0.35)


    cb2.set_label('Decrease in Black Carbon')

    font = {'family' : 'serif',
        'color'  : 'black',
        'weight' : 'bold',
        'size'   : 21,
        }

    #add plot details
    plt.title(r'Black Carbon surface concentrations changes in %s 2006 compared with %s 2006 ($\mu$gm$\^3$)'%(g,d) ,fontdict=font)
    map.drawcoastlines(linewidth=0.75)
    map.drawcountries(linewidth=0.25)
    #show plot
    plt.show()

Tags: innormmapmywithpltmplcmap
1条回答
网友
1楼 · 发布于 2024-10-03 09:12:38

您的问题的一个最小工作示例*和一些实现您所需的more options for ^{}

import pylab as plt

plt.imshow([[1,2,3],[4,5,6]])

cbar_options = {'extend':'both',
                'orientation':"horizontal",
                'shrink':0.75,
                'fraction':.10,
                'pad':.07}

cb1 = plt.colorbar(**cbar_options)
cb1.set_label('Increase in Black Carbon')

cb2 = plt.colorbar(**cbar_options)
cb2.set_label('Decrease in Black Carbon')

plt.show()

enter image description here

  • 您应该始终尝试发布一些开箱即用的代码片段。您的示例需要大量的修改,并且缺少导入和变量!在

相关问题 更多 >